11package com .github .scribejava .core .httpclient ;
22
3- import com .github .scribejava .core .model .OAuthRequest ;
3+ import com .github .scribejava .core .model .OAuthAsyncRequestCallback ;
44import com .github .scribejava .core .model .Response ;
55import com .github .scribejava .core .model .Verb ;
66import java .io .File ;
@@ -14,32 +14,89 @@ public abstract class AbstractAsyncOnlyHttpClient implements HttpClient {
1414 public Response execute (String userAgent , Map <String , String > headers , Verb httpVerb , String completeUrl ,
1515 byte [] bodyContents ) throws InterruptedException , ExecutionException , IOException {
1616
17- return executeAsync (userAgent , headers , httpVerb , completeUrl , bodyContents , null ,
18- (OAuthRequest .ResponseConverter <Response >) null ).get ();
17+ final OAuthAsyncRequestThrowableHolderCallback oAuthAsyncRequestThrowableHolderCallback
18+ = new OAuthAsyncRequestThrowableHolderCallback ();
19+
20+ final Response response = executeAsync (userAgent , headers , httpVerb , completeUrl , bodyContents ,
21+ oAuthAsyncRequestThrowableHolderCallback , null ).get ();
22+
23+ final Throwable throwable = oAuthAsyncRequestThrowableHolderCallback .getThrowable ();
24+ if (throwable != null ) {
25+ throw new ExecutionException (throwable );
26+ }
27+ return response ;
1928 }
2029
2130 @ Override
2231 public Response execute (String userAgent , Map <String , String > headers , Verb httpVerb , String completeUrl ,
2332 com .github .scribejava .core .httpclient .multipart .MultipartPayload bodyContents )
2433 throws InterruptedException , ExecutionException , IOException {
2534
26- return executeAsync (userAgent , headers , httpVerb , completeUrl , bodyContents , null ,
27- (OAuthRequest .ResponseConverter <Response >) null ).get ();
35+ final OAuthAsyncRequestThrowableHolderCallback oAuthAsyncRequestThrowableHolderCallback
36+ = new OAuthAsyncRequestThrowableHolderCallback ();
37+
38+ final Response response = executeAsync (userAgent , headers , httpVerb , completeUrl , bodyContents ,
39+ oAuthAsyncRequestThrowableHolderCallback , null ).get ();
40+
41+ final Throwable throwable = oAuthAsyncRequestThrowableHolderCallback .getThrowable ();
42+ if (throwable != null ) {
43+ throw new ExecutionException (throwable );
44+ }
45+
46+ return response ;
2847 }
2948
3049 @ Override
3150 public Response execute (String userAgent , Map <String , String > headers , Verb httpVerb , String completeUrl ,
3251 String bodyContents ) throws InterruptedException , ExecutionException , IOException {
3352
34- return executeAsync (userAgent , headers , httpVerb , completeUrl , bodyContents , null ,
35- (OAuthRequest .ResponseConverter <Response >) null ).get ();
53+ final OAuthAsyncRequestThrowableHolderCallback oAuthAsyncRequestThrowableHolderCallback
54+ = new OAuthAsyncRequestThrowableHolderCallback ();
55+
56+ final Response response = executeAsync (userAgent , headers , httpVerb , completeUrl , bodyContents ,
57+ oAuthAsyncRequestThrowableHolderCallback , null ).get ();
58+
59+ final Throwable throwable = oAuthAsyncRequestThrowableHolderCallback .getThrowable ();
60+ if (throwable != null ) {
61+ throw new ExecutionException (throwable );
62+ }
63+
64+ return response ;
3665 }
3766
3867 @ Override
3968 public Response execute (String userAgent , Map <String , String > headers , Verb httpVerb , String completeUrl ,
4069 File bodyContents ) throws InterruptedException , ExecutionException , IOException {
4170
42- return executeAsync (userAgent , headers , httpVerb , completeUrl , bodyContents , null ,
43- (OAuthRequest .ResponseConverter <Response >) null ).get ();
71+ final OAuthAsyncRequestThrowableHolderCallback oAuthAsyncRequestThrowableHolderCallback
72+ = new OAuthAsyncRequestThrowableHolderCallback ();
73+
74+ final Response response = executeAsync (userAgent , headers , httpVerb , completeUrl , bodyContents ,
75+ oAuthAsyncRequestThrowableHolderCallback , null ).get ();
76+
77+ final Throwable throwable = oAuthAsyncRequestThrowableHolderCallback .getThrowable ();
78+ if (throwable != null ) {
79+ throw new ExecutionException (throwable );
80+ }
81+
82+ return response ;
83+ }
84+
85+ private class OAuthAsyncRequestThrowableHolderCallback implements OAuthAsyncRequestCallback <Response > {
86+
87+ private Throwable throwable ;
88+
89+ @ Override
90+ public void onCompleted (Response response ) {
91+ }
92+
93+ @ Override
94+ public void onThrowable (Throwable t ) {
95+ throwable = t ;
96+ }
97+
98+ public Throwable getThrowable () {
99+ return throwable ;
100+ }
44101 }
45102}
0 commit comments