use of java.net.http.HttpRequest.BodyPublisher in project jena by apache.
the class HttpRDF method httpPostDataset.
public static void httpPostDataset(HttpClient httpClient, String url, DatasetGraph dataset, RDFFormat format, Map<String, String> httpHeaders) {
BodyPublisher bodyPublisher = datasetToHttpBody(dataset, format);
pushBody(httpClient, url, Push.POST, bodyPublisher, format, httpHeaders);
}
use of java.net.http.HttpRequest.BodyPublisher in project jena by apache.
the class HttpRDF method httpPostGraph.
public static void httpPostGraph(HttpClient httpClient, String url, Graph graph, RDFFormat format, Map<String, String> httpHeaders) {
BodyPublisher bodyPublisher = graphToHttpBody(graph, format);
pushBody(httpClient, url, Push.POST, bodyPublisher, format, httpHeaders);
}
use of java.net.http.HttpRequest.BodyPublisher in project jena by apache.
the class HttpRDF method httpPostGraphRtn.
/**
* Post a graph and expect an RDF graph back as the result.
*/
public static Graph httpPostGraphRtn(HttpClient httpClient, String url, Graph graph, RDFFormat format, Map<String, String> httpHeaders) {
BodyPublisher bodyPublisher = graphToHttpBody(graph, HttpEnv.defaultTriplesFormat);
HttpResponse<InputStream> httpResponse = pushWithResponse(httpClient, url, Push.POST, bodyPublisher, format, httpHeaders);
Graph graphResponse = GraphFactory.createDefaultGraph();
StreamRDF dest = StreamRDFLib.graph(graphResponse);
httpResponseToStreamRDF(url, httpResponse, dest);
return graphResponse;
}
use of java.net.http.HttpRequest.BodyPublisher in project openvidu-loadtest by OpenVidu.
the class CustomHttpClient method sendPost.
public HttpResponse<String> sendPost(String url, JsonObject body, File file, Map<String, String> headers) throws IOException, InterruptedException {
String boundary = "";
Builder requestBuilder = HttpRequest.newBuilder().uri(URI.create(url));
BodyPublisher postBody;
headers.forEach((k, v) -> {
requestBuilder.header(k, v);
});
if (file != null) {
boundary = new BigInteger(256, new Random()).toString();
requestBuilder.header("Content-Type", "multipart/form-data;boundary=" + boundary);
postBody = ofMimeMultipartData(Map.of("file", file.toPath()), boundary);
} else {
requestBuilder.header("Content-Type", "application/json");
postBody = HttpRequest.BodyPublishers.ofString(body.toString());
}
HttpRequest request = requestBuilder.POST(postBody).timeout(Duration.ofSeconds(60)).build();
return client.send(request, HttpResponse.BodyHandlers.ofString());
}
use of java.net.http.HttpRequest.BodyPublisher in project ignite-3 by apache.
the class IgniteCliInterfaceTest method requestBodyBytes.
private byte[] requestBodyBytes(HttpRequest capturedRequest) {
assertTrue(capturedRequest.bodyPublisher().isPresent());
BodyPublisher jdkBodyPublisher = capturedRequest.bodyPublisher().get();
ByteBuffer requestBodyBuffer = JdkFlowAdapter.flowPublisherToFlux(jdkBodyPublisher).blockFirst();
assertThat(requestBodyBuffer, is(notNullValue()));
byte[] bytes = new byte[requestBodyBuffer.remaining()];
requestBodyBuffer.get(bytes);
return bytes;
}
Aggregations