@@ -46,7 +46,8 @@ public SendResponse send() throws IOException, InterruptedException {
4646
4747 InjectionResponseParser parser = new InjectionResponseParser ();
4848
49- if (retrySettings .getMaximumNumberOfRetries () == 0 ){
49+ if (retrySettings .getMaximumNumberOfRetries () == 0 ) {
50+
5051 Response response = httpRequest .SendRequest ();
5152 return parser .Parse (response );
5253 }
@@ -56,37 +57,47 @@ public SendResponse send() throws IOException, InterruptedException {
5657 Duration waitInterval = retrySettings .getNextWaitInterval (attempts );
5758
5859 try {
60+
5961 Response response = httpRequest .SendRequest ();
60- System . out . println ( "RESPONSE : " + response . networkResponse (). code ());
62+
6163 if (ErrorStatusCodes .contains (response .networkResponse ().code ()))
6264 throw new IOException ("Received Http Status Code : " + response .networkResponse ().code ());
65+
6366 return parser .Parse (response );
67+
6468 }
6569
6670 catch (SocketTimeoutException exception )
6771 {
72+
6873 attempts ++;
69- System . out . println ( "Exception Occured in SocketTimeOutException : " + exception + " Attempt : " + attempts );
74+
7075 if (attempts > retrySettings .getMaximumNumberOfRetries ()) throw new SocketTimeoutException ();
76+
7177 TimeUnit .MILLISECONDS .sleep (waitInterval .toMillis ());
7278
7379 }
7480
7581 catch (InterruptedIOException exception )
7682 {
83+
7784 attempts ++;
78- System . out . println ( "Exception Occured in InterruptedIOException : " + exception + " Attempt : " + attempts );
85+
7986 if (attempts > retrySettings .getMaximumNumberOfRetries ()) throw new InterruptedIOException ();
87+
8088 TimeUnit .MILLISECONDS .sleep (waitInterval .toMillis ());
8189
8290 }
8391
8492 catch (IOException exception )
8593 {
94+
8695 attempts ++;
87- System . out . println ( "Exception Occured in IOException : " + exception + " Attempt : " + attempts );
96+
8897 if (attempts > retrySettings .getMaximumNumberOfRetries ()) throw new IOException (exception .getMessage ());
98+
8999 TimeUnit .MILLISECONDS .sleep (waitInterval .toMillis ());
100+
90101 }
91102
92103 } while (true );
@@ -97,69 +108,75 @@ public void sendAsync (final SendAsyncCallback callback) throws IOException, Int
97108
98109 InjectionResponseParser parser = new InjectionResponseParser ();
99110 Duration waitInterval = retrySettings .getNextWaitInterval (attempts );
100- final SendResponse [] sendResp = {new SendResponse ()};
101111
102112 httpRequest .SendAsyncRequest (new Callback () {
113+
103114 @ Override
104- public void onFailure (Call call , IOException e ) {
105- if (Exceptions .contains (e .getClass ()) && attempts <= retrySettings .getMaximumNumberOfRetries ()) {
115+ public void onResponse (Call call , Response response ) throws IOException {
116+
117+ if (ErrorStatusCodes .contains (response .networkResponse ().code ()) && attempts <= retrySettings .getMaximumNumberOfRetries ()){
106118
107- System .out .println ("Attempt : " + attempts );
108119 attempts ++;
109- System .out .println ("onFailure Exception : " + e .getClass ());
110120
111121 try {
112122
113123 TimeUnit .MILLISECONDS .sleep (waitInterval .toMillis ());
114124 sendAsync (callback );
115125
116126 }
117-
118- catch (IOException exception ) {
119- exception .printStackTrace ();
120- }
121-
122127 catch (InterruptedException interruptedException ) {
128+
123129 interruptedException .printStackTrace ();
130+
124131 }
125132
126133 }
127134
128135 else {
129136
130- attempts = retrySettings .getMaximumNumberOfRetries () + 1 ;
131- System .out .println ("Different Exception with attempt : " + attempts );
132- callback .onError (e );
137+ callback .onResponse (parser .Parse (response ));
133138
134139 }
135140
136141 }
137142
138143 @ Override
139- public void onResponse (Call call , Response response ) throws IOException {
144+ public void onFailure (Call call , IOException exception ) {
140145
141- if ( ErrorStatusCodes .contains (response . networkResponse (). code ()) && attempts <= retrySettings .getMaximumNumberOfRetries ()){
146+ if ( Exceptions .contains (exception . getClass ()) && attempts <= retrySettings .getMaximumNumberOfRetries ()) {
142147
143- System .out .println ("Attempt : " + attempts );
144148 attempts ++;
145- System . out . println ( "Response code : " + response . networkResponse (). code ());
149+
146150 try {
151+
147152 TimeUnit .MILLISECONDS .sleep (waitInterval .toMillis ());
148153 sendAsync (callback );
154+
149155 }
150- catch (InterruptedException e ) {
151- e .printStackTrace ();
156+
157+ catch (IOException ioException ) {
158+
159+ ioException .printStackTrace ();
160+
161+ }
162+
163+ catch (InterruptedException interruptedException ) {
164+
165+ interruptedException .printStackTrace ();
166+
152167 }
153168
154169 }
155170
156171 else {
157- sendResp [0 ] = parser .Parse (response );
158- System .out .println ("Response : " + sendResp [0 ]);
159- callback .onResponse (sendResp [0 ]);
172+
173+ attempts = retrySettings .getMaximumNumberOfRetries () + 1 ;
174+ callback .onError (exception );
175+
160176 }
161177
162178 }
179+
163180 });
164181
165182 }
0 commit comments