8
8
import io .refactoring .http5 .client .example .helper .BaseHttpRequestHelper ;
9
9
import io .refactoring .http5 .client .example .model .User ;
10
10
import java .net .URI ;
11
+ import java .net .URISyntaxException ;
11
12
import java .nio .ByteBuffer ;
12
13
import java .nio .charset .StandardCharsets ;
13
14
import java .security .KeyManagementException ;
@@ -424,6 +425,13 @@ private Map<Long, String> getUserWithParallelRequests(
424
425
}
425
426
}
426
427
428
+ handleFutureResults (futuresMap , userResponseMap );
429
+
430
+ return userResponseMap ;
431
+ }
432
+
433
+ private void handleFutureResults (
434
+ Map <Long , Future <SimpleHttpResponse >> futuresMap , Map <Long , String > userResponseMap ) {
427
435
log .debug ("Got {} futures." , futuresMap .size ());
428
436
429
437
for (Map .Entry <Long , Future <SimpleHttpResponse >> futureEntry : futuresMap .entrySet ()) {
@@ -441,8 +449,6 @@ private Map<Long, String> getUserWithParallelRequests(
441
449
userResponseMap .put (currentUserId , message );
442
450
}
443
451
}
444
-
445
- return userResponseMap ;
446
452
}
447
453
448
454
/**
@@ -478,18 +484,8 @@ public Map<Integer, String> executeRequestsWithInterceptors(
478
484
.build ();
479
485
for (int i = 0 ; i < count ; i ++) {
480
486
try {
481
- // Update request
482
- httpGetRequest .removeHeaders ("x-req-exec-number" );
483
- httpGetRequest .addHeader ("x-req-exec-number" , String .valueOf (i ));
484
- log .debug (
485
- "Executing {} request: {} on host {}" ,
486
- httpGetRequest .getMethod (),
487
- httpGetRequest .getUri (),
488
- httpHost );
489
-
490
487
final Future <SimpleHttpResponse > future =
491
- closeableHttpAsyncClient .execute (
492
- httpGetRequest , new SimpleHttpResponseCallback (httpGetRequest , "" ));
488
+ executeInterceptorRequest (closeableHttpAsyncClient , httpGetRequest , i , httpHost );
493
489
futuresMap .put (i , future );
494
490
} catch (RequestProcessingException e ) {
495
491
userResponseMap .put (i , e .getMessage ());
@@ -501,6 +497,32 @@ public Map<Integer, String> executeRequestsWithInterceptors(
501
497
throw new RequestProcessingException (message , e );
502
498
}
503
499
500
+ handleInterceptorFutureResults (futuresMap , userResponseMap );
501
+
502
+ return userResponseMap ;
503
+ }
504
+
505
+ private Future <SimpleHttpResponse > executeInterceptorRequest (
506
+ CloseableHttpAsyncClient closeableHttpAsyncClient ,
507
+ SimpleHttpRequest httpGetRequest ,
508
+ int i ,
509
+ HttpHost httpHost )
510
+ throws URISyntaxException {
511
+ // Update request
512
+ httpGetRequest .removeHeaders ("x-req-exec-number" );
513
+ httpGetRequest .addHeader ("x-req-exec-number" , String .valueOf (i ));
514
+ log .debug (
515
+ "Executing {} request: {} on host {}" ,
516
+ httpGetRequest .getMethod (),
517
+ httpGetRequest .getUri (),
518
+ httpHost );
519
+
520
+ return closeableHttpAsyncClient .execute (
521
+ httpGetRequest , new SimpleHttpResponseCallback (httpGetRequest , "" ));
522
+ }
523
+
524
+ private void handleInterceptorFutureResults (
525
+ Map <Integer , Future <SimpleHttpResponse >> futuresMap , Map <Integer , String > userResponseMap ) {
504
526
log .debug ("Got {} futures." , futuresMap .size ());
505
527
506
528
for (Map .Entry <Integer , Future <SimpleHttpResponse >> futureEntry : futuresMap .entrySet ()) {
@@ -514,8 +536,6 @@ public Map<Integer, String> executeRequestsWithInterceptors(
514
536
userResponseMap .put (currentRequestId , message );
515
537
}
516
538
}
517
-
518
- return userResponseMap ;
519
539
}
520
540
521
541
/**
0 commit comments