package Ġcom . ec wid . apic lient . v 3 . http transport . impl Ċ Ċ import Ġcom . ec wid . apic lient . v 3 . http transport . HttpRequest Ċ import Ġcom . ec wid . apic lient . v 3 . http transport . HttpResponse Ċ import Ġcom . ec wid . apic lient . v 3 . http transport . Http Transport Ċ import Ġorg . apache . http . Header Ċ import Ġorg . apache . http . client . HttpClient Ċ import Ġorg . apache . http . client . config . Request Config Ċ import Ġorg . apache . http . impl . client . HttpClient Builder Ċ import Ġorg . apache . http . impl . conn . Pooling HttpClient ConnectionManager Ċ import Ġjava . io . IOException Ċ Ċ private Ġconst Ġval ĠDEFAULT _ CONNECTION _ TIMEOUT Ġ= Ġ 1 0 _ 0 0 0 Ġ// Ġ 1 0 Ġsec Ċ private Ġconst Ġval ĠDEFAULT _ READ _ TIMEOUT Ġ= Ġ 6 0 _ 0 0 0 Ġ// Ġ 1 Ġmin Ċ Ċ private Ġconst Ġval ĠDEFAULT _ MAX _ CONNECTION S Ġ= Ġ 1 0 Ċ Ċ /** Ċ Ġ* ĠNumber Ġof Ġattempts Ġto Ġretry Ġrequest Ġif Ġserver Ġrespon ded Ġwith Ġ 4 2 9 Ċ Ġ*/ Ċ internal Ġconst Ġval ĠDEFAULT _ RATE _ LIMIT _ AT TEMP TS Ġ= Ġ 2 Ċ Ċ /** Ċ Ġ* ĠNumber Ġof Ġseconds Ġto Ġwait Ġuntil Ġnext Ġattempt , Ġif Ġserver Ġdidn 't Ġsend ĠRetry - After Ġheader Ċ Ġ*/ Ċ internal Ġconst Ġval ĠDEFAULT _ RATE _ LIMIT _ RETRY _ INTERVAL _ SECONDS Ġ= Ġ 1 0 L Ċ Ċ /** Ċ Ġ* ĠMax imal Ġdelay Ġin Ġseconds Ġbefore Ġnext Ġattempt Ċ Ġ*/ Ċ internal Ġconst Ġval ĠMAX _ RATE _ LIMIT _ RETRY _ INTERVAL _ SECONDS Ġ= Ġ 6 0 L Ċ Ċ val ĠEMPTY _ WAIT ING _ RE ACTION : Ġ( Long ) Ġ-> ĠUnit Ġ= Ġ{ Ġ} Ċ val ĠEMPTY _ BEFORE _ REQUEST _ ACTION : Ġ() Ġ-> ĠUnit Ġ= Ġ{ Ġ} Ċ Ċ open Ġclass ĠApache Common s HttpClient Transport ( Ċ ĉ private Ġval ĠhttpClient : ĠHttpClient Ġ= Ġbuild HttpClient (), Ċ ĉ private Ġval Ġrate Limit Retry Strategy : ĠRate Limit Retry Strategy Ġ= ĠSleep For Retry After RateLimit Retry Strategy (), Ċ ) Ġ: ĠHttp Transport Ġ{ ĊĊ ĉ constructor ( Ċĉ ĉ httpClient : ĠHttpClient , Ċĉ ĉ default RateLimit Attempts : ĠInt Ġ= ĠDEFAULT _ RATE _ LIMIT _ AT TEMP TS , Ċĉ ĉ default RateLimit Retry Interval : ĠLong Ġ= ĠDEFAULT _ RATE _ LIMIT _ RETRY _ INTERVAL _ SECONDS , Ċĉ ĉ max RateLimit Retry Interval : ĠLong Ġ= ĠMAX _ RATE _ LIMIT _ RETRY _ INTERVAL _ SECONDS , Ċĉ ĉ on Every Second Of Waiting : Ġ( Long ) Ġ-> ĠUnit Ġ= ĠEMPTY _ WAIT ING _ RE ACTION , Ċĉ ĉ before Each Request Attempt : Ġ() Ġ-> ĠUnit Ġ= ĠEMPTY _ BEFORE _ REQUEST _ ACTION , Ċ ĉ ) Ġ: Ġthis ( Ċĉ ĉ httpClient , Ċĉ ĉ rate Limit Retry Strategy Ġ= ĠSleep For Retry After RateLimit Retry Strategy ( Ċĉĉ ĉ default RateLimit Attempts Ġ= Ġdefault RateLimit Attempts , Ċĉĉ ĉ default RateLimit Retry Interval Ġ= Ġdefault RateLimit Retry Interval , Ċĉĉ ĉ max RateLimit Retry Interval Ġ= Ġmax RateLimit Retry Interval , Ċĉĉ ĉ on Every Second Of Waiting Ġ= Ġon Every Second Of Waiting , Ċĉĉ ĉ before Each Request Attempt Ġ= ĠbeforeEach Request Attempt Ċĉ ĉ ) Ċ ĉ ) ĊĊ ĉ constructor ( Ċĉ ĉ default Connection Timeout : ĠInt Ġ= ĠDEFAULT _ CONNECTION _ TIMEOUT , Ċĉ ĉ default Read Timeout : ĠInt Ġ= ĠDEFAULT _ READ _ TIMEOUT , Ċĉ ĉ default Max Connections : ĠInt Ġ= ĠDEFAULT _ MAX _ CONNECTION S , Ċĉ ĉ default Headers : ĠList < Header > Ġ= Ġempty List (), Ċĉ ĉ rate Limit Retry Strategy : ĠRate Limit Retry Strategy Ċ ĉ ) Ġ: Ġthis ( Ċĉ ĉ httpClient Ġ= Ġbuild HttpClient ( Ċĉĉ ĉ default Connection Timeout Ġ= Ġdefault Connection Timeout , Ċĉĉ ĉ default Read Timeout Ġ= Ġdefault Read Timeout , Ċĉĉ ĉ default Max Connections Ġ= Ġdefault Max Connections , Ċĉĉ ĉ default Headers Ġ= Ġdefault Headers Ċĉ ĉ ), Ċĉ ĉ rate Limit Retry Strategy Ġ= Ġrate Limit Retry Strategy Ċ ĉ ) ĊĊ ĉ constructor ( Ċĉ ĉ default Connection Timeout : ĠInt Ġ= ĠDEFAULT _ CONNECTION _ TIMEOUT , Ċĉ ĉ default Read Timeout : ĠInt Ġ= ĠDEFAULT _ READ _ TIMEOUT , Ċĉ ĉ default Max Connections : ĠInt Ġ= ĠDEFAULT _ MAX _ CONNECTION S , Ċĉ ĉ default RateLimit Attempts : ĠInt Ġ= ĠDEFAULT _ RATE _ LIMIT _ AT TEMP TS , Ċĉ ĉ default RateLimit Retry Interval : ĠLong Ġ= ĠDEFAULT _ RATE _ LIMIT _ RETRY _ INTERVAL _ SECONDS , Ċĉ ĉ max RateLimit Retry Interval : ĠLong Ġ= ĠMAX _ RATE _ LIMIT _ RETRY _ INTERVAL _ SECONDS , Ċĉ ĉ default Headers : ĠList < Header > Ġ= Ġempty List (), Ċĉ ĉ on Every Second Of Waiting : Ġ( Long ) Ġ-> ĠUnit Ġ= ĠEMPTY _ WAIT ING _ RE ACTION , Ċĉ ĉ before Each Request Attempt : Ġ() Ġ-> ĠUnit Ġ= ĠEMPTY _ BEFORE _ REQUEST _ ACTION , Ċ ĉ ) Ġ: Ġthis ( Ċĉ ĉ httpClient Ġ= Ġbuild HttpClient ( Ċĉĉ ĉ default Connection Timeout Ġ= Ġdefault Connection Timeout , Ċĉĉ ĉ default Read Timeout Ġ= Ġdefault Read Timeout , Ċĉĉ ĉ default Max Connections Ġ= Ġdefault Max Connections , Ċĉĉ ĉ default Headers Ġ= Ġdefault Headers Ċĉ ĉ ), Ċĉ ĉ rate Limit Retry Strategy Ġ= ĠSleep For Retry After RateLimit Retry Strategy ( Ċĉĉ ĉ default RateLimit Attempts Ġ= Ġdefault RateLimit Attempts , Ċĉĉ ĉ default RateLimit Retry Interval Ġ= Ġdefault RateLimit Retry Interval , Ċĉĉ ĉ max RateLimit Retry Interval Ġ= Ġmax RateLimit Retry Interval , Ċĉĉ ĉ on Every Second Of Waiting Ġ= Ġon Every Second Of Waiting , Ċĉĉ ĉ before Each Request Attempt Ġ= ĠbeforeEach Request Attempt , Ċĉ ĉ ) Ċ ĉ ) ĊĊ ĉ override Ġfun Ġmake HttpRequest ( httpRequest : ĠHttpRequest ): ĠHttpResponse Ġ{ Ċĉ ĉ return Ġtry Ġ{ Ċĉĉ ĉ rate Limit Retry Strategy . make HttpRequest ( httpClient , ĠhttpRequest ) Ċĉ ĉ } Ġcatch Ġ( e : ĠIOException ) Ġ{ Ċĉĉ ĉ HttpResponse . Transport Error ( e ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ comp anion Ġobject Ġ{ ĊĊĉ ĉ private Ġfun Ġbuild HttpClient ( Ċĉĉ ĉ default Connection Timeout : ĠInt Ġ= ĠDEFAULT _ CONNECTION _ TIMEOUT , Ċĉĉ ĉ default Read Timeout : ĠInt Ġ= ĠDEFAULT _ READ _ TIMEOUT , Ċĉĉ ĉ default Max Connections : ĠInt Ġ= ĠDEFAULT _ MAX _ CONNECTION S , Ċĉĉ ĉ default Headers : ĠList < Header > Ġ= Ġempty List (), Ċĉ ĉ ): ĠHttpClient Ġ{ Ċĉĉ ĉ val Ġconnection Manager Ġ= ĠPool ing HttpClient ConnectionManager (). apply Ġ{ Ċĉĉĉ ĉ max Total Ġ= Ġdefault Max Connections Ċĉĉĉ ĉ default Max Per Route Ġ= Ġdefault Max Connections Ċĉĉ ĉ } ĊĊĉĉ ĉ val Ġrequest Config Ġ= ĠRequest Config . custom () Ċĉĉĉ ĉ . set Connect Timeout ( default Connection Timeout ) Ċĉĉĉ ĉ . setConnection Request Timeout ( default Connection Timeout ) Ċĉĉĉ ĉ . set Socket Timeout ( default Read Timeout ) Ċĉĉĉ ĉ . build () ĊĊĉĉ ĉ val ĠhttpClient Builder Ġ= ĠHttpClient Builder . create () Ċĉĉĉ ĉ . set ConnectionManager ( connection Manager ) Ċĉĉĉ ĉ . setDefault Request Config ( request Config ) Ċĉĉ ĉ // ĠTODO Ġ. set Retry Handler () Ċĉĉ ĉ // ĠTODO Ġ. set Service Unavailable Retry Strategy () Ċĉĉ ĉ if Ġ( default Headers . isNotEmpty ()) Ġ{ Ċĉĉĉ ĉ httpClient Builder . setDefault Headers ( default Headers ) Ċĉĉ ĉ } Ċĉĉ ĉ return ĠhttpClient Builder . build () Ċĉ ĉ } Ċ ĉ } Ċ } Ċ