Search in sources :

Example 6 with BodyPublisher

use of java.net.http.HttpRequest.BodyPublisher in project jena by apache.

the class TestWebappServerReadOnly method dataset_w_readonly_POST.

@Test
public void dataset_w_readonly_POST() {
    // Try to write
    HttpTest.execWithHttpException(HttpSC.METHOD_NOT_ALLOWED_405, () -> {
        BodyPublisher bodyPublisher = BodyPublishers.ofString("");
        HttpOp.httpPost(ServerCtl.urlDataset(), null, bodyPublisher);
    });
}
Also used : BodyPublisher(java.net.http.HttpRequest.BodyPublisher) FusekiTest(org.apache.jena.fuseki.test.FusekiTest) Test(org.junit.Test) HttpTest(org.apache.jena.fuseki.test.HttpTest)

Example 7 with BodyPublisher

use of java.net.http.HttpRequest.BodyPublisher in project jena by apache.

the class TestAdmin method addTestDataset.

private static void addTestDataset(String filename) {
    try {
        Path f = Path.of(filename);
        BodyPublisher body = BodyPublishers.ofFile(f);
        String ct = WebContent.contentTypeTurtle;
        httpPost(ServerCtl.urlRoot() + "$/" + opDatasets, ct, body);
    } catch (FileNotFoundException e) {
        IO.exception(e);
    }
}
Also used : Path(java.nio.file.Path) BodyPublisher(java.net.http.HttpRequest.BodyPublisher) FileNotFoundException(java.io.FileNotFoundException)

Example 8 with BodyPublisher

use of java.net.http.HttpRequest.BodyPublisher in project feign by OpenFeign.

the class Http2Client method newRequestBuilder.

private Builder newRequestBuilder(Request request, Options options) throws URISyntaxException {
    URI uri = new URI(request.url());
    final BodyPublisher body;
    final byte[] data = request.body();
    if (data == null) {
        body = BodyPublishers.noBody();
    } else {
        body = BodyPublishers.ofByteArray(data);
    }
    final Builder requestBuilder = HttpRequest.newBuilder().uri(uri).timeout(Duration.ofMillis(options.readTimeoutMillis())).version(client.version());
    final Map<String, Collection<String>> headers = filterRestrictedHeaders(request.headers());
    if (!headers.isEmpty()) {
        requestBuilder.headers(asString(headers));
    }
    switch(request.httpMethod()) {
        case GET:
            return requestBuilder.GET();
        case POST:
            return requestBuilder.POST(body);
        case PUT:
            return requestBuilder.PUT(body);
        case DELETE:
            return requestBuilder.DELETE();
        default:
            // fall back scenario, http implementations may restrict some methods
            return requestBuilder.method(request.httpMethod().toString(), body);
    }
}
Also used : Builder(java.net.http.HttpRequest.Builder) BodyPublisher(java.net.http.HttpRequest.BodyPublisher) Collection(java.util.Collection) URI(java.net.URI)

Example 9 with BodyPublisher

use of java.net.http.HttpRequest.BodyPublisher in project jena by apache.

the class HttpRDF method httpPutGraph.

public static void httpPutGraph(HttpClient httpClient, String url, Graph graph, RDFFormat format, Map<String, String> httpHeaders) {
    BodyPublisher bodyPublisher = graphToHttpBody(graph, format);
    pushBody(httpClient, url, Push.PUT, bodyPublisher, format, httpHeaders);
}
Also used : BodyPublisher(java.net.http.HttpRequest.BodyPublisher)

Example 10 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)

Aggregations

BodyPublisher (java.net.http.HttpRequest.BodyPublisher)13 FusekiTest (org.apache.jena.fuseki.test.FusekiTest)4 HttpTest (org.apache.jena.fuseki.test.HttpTest)4 Test (org.junit.Test)4 FileNotFoundException (java.io.FileNotFoundException)2 Builder (java.net.http.HttpRequest.Builder)2 Path (java.nio.file.Path)2 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 URI (java.net.URI)1 HttpRequest (java.net.http.HttpRequest)1 Collection (java.util.Collection)1 Random (java.util.Random)1 Graph (org.apache.jena.graph.Graph)1 StreamRDF (org.apache.jena.riot.system.StreamRDF)1 NotFoundException (org.apache.jena.shared.NotFoundException)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1