@@ -171,8 +171,7 @@ public HttpResponse execute() throws IOException {
171
171
172
172
@ Override
173
173
public HttpResponse executeAsync (Consumer <? super HttpResponse > succeed ,
174
- BiConsumer <? super HttpResponse , Throwable > fail ,
175
- BiConsumer <? super HttpResponse , Throwable > always ) {
174
+ BiConsumer <? super HttpResponse , Throwable > fail , BiConsumer <? super HttpResponse , Throwable > always ) {
176
175
isAsync = (succeed != null || fail != null || always != null );
177
176
this .succeed = succeed ;
178
177
this .fail = fail ;
@@ -200,7 +199,6 @@ public void run() {
200
199
return r ;
201
200
}
202
201
203
-
204
202
@ SuppressWarnings ("resource" )
205
203
public Response fulfillGet () throws Exception {
206
204
URI uri = getUri ();
@@ -282,7 +280,7 @@ public class Response implements HttpResponse {
282
280
private int state = 0 ;
283
281
284
282
ByteArrayInputStream inputStream ;
285
-
283
+
286
284
private Throwable exception ;
287
285
288
286
/**
@@ -333,6 +331,11 @@ public void accept(byte[] t) {
333
331
return this ;
334
332
}
335
333
334
+ /**
335
+ * Make the proper callback, depending upon response code and exception state.
336
+ *
337
+ * @param ok
338
+ */
336
339
protected void doCallback (boolean ok ) {
337
340
ok &= (exception == null );
338
341
if (ok && succeed != null )
@@ -343,22 +346,13 @@ else if (!ok && fail != null)
343
346
always .accept (this , exception );
344
347
}
345
348
346
- @ Override
347
- public int getStatusCode () {
348
- try {
349
- return (state != 0 ? state : conn .getResponseCode ());
350
- } catch (Throwable e ) {
351
- handleError (e );
352
- return state ;
353
- }
354
- }
355
-
356
349
/**
350
+ * Handle any errors that arise in the process of processing this request.
357
351
*
358
352
* @param e
359
353
* @return true if aSynchronous and has been handled
360
354
*/
361
- private boolean handleError (Throwable e ) {
355
+ protected boolean handleError (Throwable e ) {
362
356
exception = e ;
363
357
// setting e = null to indicated handled.
364
358
if (isAsync ) {
@@ -374,6 +368,16 @@ private boolean handleError(Throwable e) {
374
368
return e == null ;
375
369
}
376
370
371
+ @ Override
372
+ public int getStatusCode () {
373
+ try {
374
+ return (state != 0 ? state : conn .getResponseCode ());
375
+ } catch (Throwable e ) {
376
+ handleError (e );
377
+ return state ;
378
+ }
379
+ }
380
+
377
381
@ Override
378
382
public Map <String , String > getHeaders () {
379
383
Map <String , String > headers = new LinkedHashMap <>();
0 commit comments