play.libs.ws.ahc.AhcWSRequest Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) from 2022 The Play Framework Contributors , 2011-2021 Lightbend Inc.
*/
package play.libs.ws.ahc;
import com.fasterxml.jackson.databind.JsonNode;
import java.io.File;
import java.io.InputStream;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletionStage;
import java.util.function.Function;
import org.apache.pekko.stream.javadsl.Source;
import org.apache.pekko.util.ByteString;
import org.w3c.dom.Document;
import play.libs.ws.*;
import play.mvc.Http;
/** A Play WS request backed by AsyncHTTPClient implementation. */
public class AhcWSRequest implements WSRequest {
private static WSBodyWritables writables = new WSBodyWritables() {};
private final AhcWSClient client;
private final StandaloneAhcWSRequest request;
private final Function responseFunction = AhcWSResponse::new;
private final Function converter =
new Function() {
public WSRequest apply(StandaloneWSRequest standaloneWSRequest) {
final StandaloneAhcWSRequest plainAhcWSRequest =
(StandaloneAhcWSRequest) standaloneWSRequest;
return new AhcWSRequest(client, plainAhcWSRequest);
}
};
AhcWSRequest(AhcWSClient client, StandaloneAhcWSRequest request) {
this.client = client;
this.request = request;
}
@Override
public CompletionStage get() {
return request.get().thenApply(responseFunction);
}
@Override
public CompletionStage patch(BodyWritable body) {
return request.patch(body).thenApply(responseFunction);
}
@Override
public CompletionStage patch(String string) {
return request.patch(writables.body(string)).thenApply(responseFunction);
}
@Override
public CompletionStage patch(JsonNode jsonNode) {
return request.patch(writables.body(jsonNode)).thenApply(responseFunction);
}
@Override
public CompletionStage patch(Document doc) {
return request.patch(writables.body(doc)).thenApply(responseFunction);
}
@Deprecated
@Override
public CompletionStage patch(InputStream inputStream) {
return request.patch(writables.body(() -> inputStream)).thenApply(responseFunction);
}
@Override
public CompletionStage patch(File file) {
return request.patch(writables.body(file)).thenApply(responseFunction);
}
@Override
public CompletionStage patch(
Source super Http.MultipartFormData.Part
© 2015 - 2024 Weber Informatics LLC | Privacy Policy