|
|
@ -187,11 +187,15 @@ public class WebClient {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private <T> HttpResponse<T> handleRequest(boolean async, HttpRequest hreq, HttpResponse.BodyHandler<T> bodyHandler, Consumer<HttpResponse<T>> respHandler) throws Exception {
|
|
|
|
private <T> HttpResponse<T> handleRequest(boolean async, HttpRequest hreq, HttpResponse.BodyHandler<T> bodyHandler, Consumer<HttpResponse<T>> respHandler) throws Exception {
|
|
|
|
|
|
|
|
Log.get(getClass()).debug("Sending request");
|
|
|
|
if (!async) {
|
|
|
|
if (!async) {
|
|
|
|
return client().send(hreq, bodyHandler);
|
|
|
|
HttpResponse<T> resp = client().send(hreq, bodyHandler);
|
|
|
|
|
|
|
|
Log.get(getClass()).debug("Received response");
|
|
|
|
|
|
|
|
return resp;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
CompletableFuture<HttpResponse<T>> future = client().sendAsync(hreq, bodyHandler);
|
|
|
|
CompletableFuture<HttpResponse<T>> future = client().sendAsync(hreq, bodyHandler);
|
|
|
|
future.thenApply(resp -> {
|
|
|
|
future.thenApply(resp -> {
|
|
|
|
|
|
|
|
Log.get(getClass()).debug("Received response");
|
|
|
|
respHandler.accept(resp);
|
|
|
|
respHandler.accept(resp);
|
|
|
|
return resp;
|
|
|
|
return resp;
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -376,8 +380,7 @@ public class WebClient {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public Request json(JSON json) {
|
|
|
|
public Request json(JSON json) {
|
|
|
|
this.json = json;
|
|
|
|
this.json = json;
|
|
|
|
contentType(ContentType.JSON);
|
|
|
|
return contentType(ContentType.JSON);
|
|
|
|
return header("Accept", ContentType.JSON.type);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private JSON json() {
|
|
|
|
private JSON json() {
|
|
|
@ -497,13 +500,13 @@ public class WebClient {
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest post() {
|
|
|
|
HttpRequest post() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
HttpRequest.Builder builder = HttpRequest.newBuilder(URI.create(uri));
|
|
|
|
HttpRequest.Builder builder = HttpRequest.newBuilder(URI.create(uri));
|
|
|
|
builder.POST(bodyPublisher(contentType()));
|
|
|
|
builder.POST(bodyPublisher(contentType()));
|
|
|
|
|
|
|
|
|
|
|
|
if (headers != null)
|
|
|
|
if (headers != null)
|
|
|
|
headers.forEach((k, v) -> builder.header(k, v));
|
|
|
|
headers.forEach((k, v) -> builder.header(k, v));
|
|
|
|
|
|
|
|
|
|
|
|
return builder.build();
|
|
|
|
return builder.build();
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw Assert.runtimeException(e);
|
|
|
|
throw Assert.runtimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|