Skip to content

Commit a662a0d

Browse files
committed
Merge branch 'issue-587-async-header-fix' of https://github.com/breadfan/scribejava into breadfan-issue-587-async-header-fix
2 parents edec091 + 4a2427d commit a662a0d

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

scribejava-core/src/main/java/com/github/scribejava/core/model/OAuthRequestAsync.java

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package com.github.scribejava.core.model;
22

3+
import com.github.scribejava.core.exceptions.OAuthException;
4+
import com.github.scribejava.core.oauth.OAuthService;
35
import com.ning.http.client.AsyncCompletionHandler;
46
import com.ning.http.client.AsyncHttpClient;
57
import com.ning.http.client.FluentCaseInsensitiveStringsMap;
68
import com.ning.http.client.ProxyServer;
9+
710
import java.io.IOException;
11+
import java.util.Collection;
812
import java.util.HashMap;
913
import java.util.List;
14+
import java.util.ArrayList;
1015
import java.util.Map;
1116
import java.util.concurrent.Future;
12-
import com.github.scribejava.core.exceptions.OAuthException;
13-
import com.github.scribejava.core.oauth.OAuthService;
1417

1518
public class OAuthRequestAsync extends AbstractRequest {
1619

@@ -53,10 +56,16 @@ public <T> Future<T> sendAsync(OAuthAsyncRequestCallback<T> callback, ResponseCo
5356
final AsyncHttpClient.BoundRequestBuilder boundRequestBuilder;
5457
switch (getVerb()) {
5558
case GET:
56-
boundRequestBuilder = service.getAsyncHttpClient().prepareGet(completeUrl);
59+
boundRequestBuilder = service.getAsyncHttpClient()
60+
.prepareGet(completeUrl)
61+
.setHeaders(mapHeaders());
62+
5763
break;
5864
case POST:
59-
boundRequestBuilder = service.getAsyncHttpClient().preparePost(completeUrl).setBody(getBodyContents());
65+
boundRequestBuilder = service.getAsyncHttpClient().preparePost(completeUrl)
66+
.setBody(getBodyContents())
67+
.setHeaders(mapHeaders());
68+
6069
break;
6170
default:
6271
throw new IllegalArgumentException("message build error: unknown verb type");
@@ -67,6 +76,26 @@ public <T> Future<T> sendAsync(OAuthAsyncRequestCallback<T> callback, ResponseCo
6776
return boundRequestBuilder.execute(new OAuthAsyncCompletionHandler<>(callback, converter));
6877
}
6978

79+
public Future<Response> sendAsync(OAuthAsyncRequestCallback<Response> callback) {
80+
return sendAsync(callback, RESPONSE_CONVERTER, null);
81+
}
82+
83+
public Future<Response> sendAsync(OAuthAsyncRequestCallback<Response> callback, ProxyServer proxyServer) {
84+
return sendAsync(callback, RESPONSE_CONVERTER, proxyServer);
85+
}
86+
87+
private Map<String, Collection<String>> mapHeaders() {
88+
final Map<String, String> headers = getHeaders();
89+
final Map<String, Collection<String>> mapped = new HashMap<>();
90+
91+
for(Map.Entry<String, String> entry: headers.entrySet()) {
92+
final ArrayList<String> list = new ArrayList<>();
93+
list.add(entry.getValue());
94+
mapped.put(entry.getKey(), list);
95+
}
96+
return mapped;
97+
}
98+
7099
private static class OAuthAsyncCompletionHandler<T> extends AsyncCompletionHandler<T> {
71100

72101
private final OAuthAsyncRequestCallback<T> callback;
@@ -94,14 +123,6 @@ public void onThrowable(Throwable t) {
94123
}
95124
};
96125

97-
public Future<Response> sendAsync(OAuthAsyncRequestCallback<Response> callback) {
98-
return sendAsync(callback, RESPONSE_CONVERTER, null);
99-
}
100-
101-
public Future<Response> sendAsync(OAuthAsyncRequestCallback<Response> callback, ProxyServer proxyServer) {
102-
return sendAsync(callback, RESPONSE_CONVERTER, proxyServer);
103-
}
104-
105126
public interface ResponseConverter<T> {
106127

107128
T convert(com.ning.http.client.Response response) throws IOException;

0 commit comments

Comments
 (0)