Search in sources :

Example 11 with BodyPublisher

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);
}
Also used : BodyPublisher(java.net.http.HttpRequest.BodyPublisher)

Example 12 with BodyPublisher

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);
}
Also used : BodyPublisher(java.net.http.HttpRequest.BodyPublisher)

Example 13 with BodyPublisher

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;
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) StreamRDF(org.apache.jena.riot.system.StreamRDF) InputStream(java.io.InputStream) BodyPublisher(java.net.http.HttpRequest.BodyPublisher)

Example 14 with BodyPublisher

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());
}
Also used : HttpRequest(java.net.http.HttpRequest) Random(java.util.Random) Builder(java.net.http.HttpRequest.Builder) BodyPublisher(java.net.http.HttpRequest.BodyPublisher) BigInteger(java.math.BigInteger)

Example 15 with BodyPublisher

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;
}
Also used : BodyPublisher(java.net.http.HttpRequest.BodyPublisher) ByteBuffer(java.nio.ByteBuffer)

Aggregations

BodyPublisher (java.net.http.HttpRequest.BodyPublisher)17 FusekiTest (org.apache.jena.fuseki.test.FusekiTest)4 HttpTest (org.apache.jena.fuseki.test.HttpTest)4 Test (org.junit.Test)4 Builder (java.net.http.HttpRequest.Builder)3 FileNotFoundException (java.io.FileNotFoundException)2 HttpRequest (java.net.http.HttpRequest)2 Path (java.nio.file.Path)2 WorkflowIdAndStatus (ca.on.oicr.gsi.shesmu.cromwell.WorkflowIdAndStatus)1 MultiPartBodyPublisher (ca.on.oicr.gsi.shesmu.plugin.MultiPartBodyPublisher)1 JsonBodyHandler (ca.on.oicr.gsi.shesmu.plugin.json.JsonBodyHandler)1 HttpRequest (com.algolia.search.models.HttpRequest)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 URI (java.net.URI)1 ByteBuffer (java.nio.ByteBuffer)1 Collection (java.util.Collection)1 Random (java.util.Random)1