1
1
package com .github .scribejava .core .httpclient ;
2
2
3
- import com .github .scribejava .core .model .OAuthRequest ;
3
+ import com .github .scribejava .core .model .OAuthAsyncRequestCallback ;
4
4
import com .github .scribejava .core .model .Response ;
5
5
import com .github .scribejava .core .model .Verb ;
6
6
import java .io .File ;
@@ -14,32 +14,89 @@ public abstract class AbstractAsyncOnlyHttpClient implements HttpClient {
14
14
public Response execute (String userAgent ,Map <String ,String >headers ,Verb httpVerb ,String completeUrl ,
15
15
byte []bodyContents )throws InterruptedException ,ExecutionException ,IOException {
16
16
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 ;
19
28
}
20
29
21
30
@ Override
22
31
public Response execute (String userAgent ,Map <String ,String >headers ,Verb httpVerb ,String completeUrl ,
23
32
com .github .scribejava .core .httpclient .multipart .MultipartPayload bodyContents )
24
33
throws InterruptedException ,ExecutionException ,IOException {
25
34
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 ;
28
47
}
29
48
30
49
@ Override
31
50
public Response execute (String userAgent ,Map <String ,String >headers ,Verb httpVerb ,String completeUrl ,
32
51
String bodyContents )throws InterruptedException ,ExecutionException ,IOException {
33
52
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 ;
36
65
}
37
66
38
67
@ Override
39
68
public Response execute (String userAgent ,Map <String ,String >headers ,Verb httpVerb ,String completeUrl ,
40
69
File bodyContents )throws InterruptedException ,ExecutionException ,IOException {
41
70
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
+ }
44
101
}
45
102
}