* Asynchronous GET request.
*
* @param callback callback to be invoked, asynchronously, when the request completes
- * @param path context uri path.
+ * @param path context uri path
+ * @param headers request headers
*
* @return future that can be used to cancel the request or await the response
*/
- Future<Response> get(InvocationCallback<Response> callback, String path);
+ Future<Response> get(InvocationCallback<Response> callback, String path, Map<String, Object> headers);
/**
* Asynchronous GET request.
*
* @param callback callback to be invoked, asynchronously, when the request completes
+ * @param headers request headers
* @return future that can be used to cancel the request or await the response
*/
- Future<Response> get(InvocationCallback<Response> callback);
+ Future<Response> get(InvocationCallback<Response> callback, Map<String, Object> headers);
/**
* PUT request.
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
+import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.Future;
}
@Override
- public Future<Response> get(InvocationCallback<Response> callback, String path) {
+ public Future<Response> get(InvocationCallback<Response> callback, String path, Map<String, Object> headers) {
+ Map<String, Object> headers2 = (headers != null ? headers : Collections.emptyMap());
+
if (!StringUtils.isBlank(path)) {
- return this.client.target(this.baseUrl).path(path).request().async().get(callback);
+ return getBuilder(path, headers2).async().get(callback);
} else {
- return this.client.target(this.baseUrl).request().async().get(callback);
+ return get(callback, headers2);
}
}
@Override
- public Future<Response> get(InvocationCallback<Response> callback) {
- return this.client.target(this.baseUrl).request().async().get(callback);
+ public Future<Response> get(InvocationCallback<Response> callback, Map<String, Object> headers) {
+ Builder builder = this.client.target(this.baseUrl).request();
+ if (headers != null) {
+ headers.forEach(builder::header);
+ }
+ return builder.async().get(callback);
}
@Override
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
+import java.util.TreeMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.client.Entity;
final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
6666);
MyCallback callback = new MyCallback();
- final Response response = client.get(callback, HELLO).get();
+ final Response response = client.get(callback, HELLO, new TreeMap<>()).get();
verifyCallback("testHttpGetNoAuthClientAsync", callback, response);
final HttpClient client = getAuthHttpClient();
MyCallback callback = new MyCallback();
- final Response response = client.get(callback, HELLO).get();
+ final Response response = client.get(callback, HELLO, null).get();
verifyCallback("testHttpAsyncAuthClient", callback, response);
// try it asynchronously, too
MyCallback callback = new MyCallback();
- response = clientPap.get(callback).get();
+ response = clientPap.get(callback, null).get();
verifyCallback("testHttpAuthClientProps", callback, response);
assertEquals(200, response.getStatus());
// try it asynchronously, with empty path
callback = new MyCallback();
- response = clientPap.get(callback, "").get();
+ response = clientPap.get(callback, "", null).get();
verifyCallback("testHttpAuthClientProps - empty path", callback, response);
assertEquals(200, response.getStatus());
}