Search in sources :

Example 31 with HttpClient

use of java.net.http.HttpClient in project jena by apache.

the class ExFuseki_10_Https_Setup method client.

private static void client() {
    // Need to provide a suitable HttpClient that can handle https.
    // Allow self-signed
    HttpClient hc = trustLocalhostUnsigned().build();
    RDFConnection connSingle = RDFConnectionFuseki.create().httpClient(hc).destination("https://localhost:3443/ds").build();
    try (RDFConnection conn = connSingle) {
        QueryExecution qExec = conn.query("ASK{}");
        QueryExecUtils.executeQuery(qExec);
    }
}
Also used : RDFConnection(org.apache.jena.rdfconnection.RDFConnection) HttpClient(java.net.http.HttpClient) QueryExecution(org.apache.jena.query.QueryExecution)

Example 32 with HttpClient

use of java.net.http.HttpClient in project jena by apache.

the class ExFuseki_09_Https_Auth method client.

private static void client(SSLContext sslContext) {
    Authenticator authenticator1 = AuthLib.authenticator(USER, PASSWORD);
    HttpClient hc = HttpClient.newBuilder().authenticator(authenticator1).connectTimeout(Duration.ofSeconds(10)).sslContext(sslContext).build();
    System.out.println("Good client set up");
    RDFConnection connSingle = RDFConnectionFuseki.create().httpClient(hc).destination("https://localhost:3443/ds").build();
    try (RDFConnection conn = connSingle) {
        QueryExecution qExec = conn.query("ASK{}");
        QueryExecUtils.executeQuery(qExec);
    }
    System.out.println("Bad client set up");
    Authenticator authenticator2 = AuthLib.authenticator(USER, "wrong-trousers-gromit");
    HttpClient hc2 = HttpClient.newBuilder().authenticator(authenticator2).connectTimeout(Duration.ofSeconds(10)).sslContext(sslContext).build();
    try (RDFConnection conn = RDFConnectionFuseki.create().httpClient(hc2).destination("https://localhost:3443/ds").build()) {
        QueryExecution qExec = conn.query("ASK{}");
        QueryExecUtils.executeQuery(qExec);
    } catch (Exception ex) {
        System.out.println(ex);
    }
}
Also used : RDFConnection(org.apache.jena.rdfconnection.RDFConnection) HttpClient(java.net.http.HttpClient) Authenticator(java.net.Authenticator) QueryExecution(org.apache.jena.query.QueryExecution)

Example 33 with HttpClient

use of java.net.http.HttpClient in project jena by apache.

the class TestSecurityConfig method access_serverNone_db1.

@Test
public void access_serverNone_db1() {
    test("testing/Access/config-server-0.ttl", (fusekiServer) -> {
        // db1 - secured - try no user
        try (RDFConnection conn = RDFConnectionRemote.newBuilder().destination(datasetURL(fusekiServer, "database1")).build()) {
            expectQuery401(() -> conn.queryAsk("ASK{}"));
        }
        // db1 - secured - try wrong user
        HttpClient hcUser2 = LibSec.httpClient(authSetup2(fusekiServer));
        try (RDFConnection conn = RDFConnectionRemote.newBuilder().destination(datasetURL(fusekiServer, "database1")).httpClient(hcUser2).build()) {
            expectQuery403(() -> conn.queryAsk("ASK{}"));
        }
        // db1 - secured - with user
        HttpClient hcUser1 = LibSec.httpClient(authSetup1(fusekiServer));
        try (RDFConnection conn = RDFConnectionRemote.newBuilder().destination(datasetURL(fusekiServer, "database1")).httpClient(hcUser1).build()) {
            conn.queryAsk("ASK{}");
        }
    });
}
Also used : RDFConnection(org.apache.jena.rdfconnection.RDFConnection) HttpClient(java.net.http.HttpClient) Test(org.junit.Test) HttpTest(org.apache.jena.fuseki.test.HttpTest)

Example 34 with HttpClient

use of java.net.http.HttpClient in project jena by apache.

the class DSP method PUT.

/**
 * PUT the contents of a file using the filename extension to determine the
 * Content-Type to use if not already set.
 * <p>
 * This operation does not parse the file.
 */
public void PUT(String file) {
    String fileExtContentType = contentTypeFromFilename(file);
    HttpClient hc = requestHttpClient(serviceEndpoint, serviceEndpoint);
    uploadQuads(hc, serviceEndpoint, file, fileExtContentType, httpHeaders, Push.PUT);
}
Also used : HttpClient(java.net.http.HttpClient)

Example 35 with HttpClient

use of java.net.http.HttpClient in project jena by apache.

the class DSP method POST.

/**
 * POST the contents of a file using the filename extension to determine the
 * Content-Type to use if not already set.
 * <p>
 * This operation does not parse the file.
 */
public void POST(String file) {
    String fileExtContentType = contentTypeFromFilename(file);
    HttpClient hc = requestHttpClient(serviceEndpoint, serviceEndpoint);
    uploadQuads(hc, serviceEndpoint, file, fileExtContentType, httpHeaders, Push.POST);
}
Also used : HttpClient(java.net.http.HttpClient)

Aggregations

HttpClient (java.net.http.HttpClient)42 Authenticator (java.net.Authenticator)11 HttpRequest (java.net.http.HttpRequest)8 HttpResponse (java.net.http.HttpResponse)6 URI (java.net.URI)4 RDFConnection (org.apache.jena.rdfconnection.RDFConnection)4 RDFFormat (org.apache.jena.riot.RDFFormat)4 Context (org.apache.jena.sparql.util.Context)4 SerializedClassRunner (io.pravega.test.common.SerializedClassRunner)3 TestUtils (io.pravega.test.common.TestUtils)3 URISyntaxException (java.net.URISyntaxException)3 Duration (java.time.Duration)3 Pattern (java.util.regex.Pattern)3 GZIPInputStream (java.util.zip.GZIPInputStream)3 Cleanup (lombok.Cleanup)3 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)3 Assert.assertTrue (org.junit.Assert.assertTrue)3 Test (org.junit.Test)3 RunWith (org.junit.runner.RunWith)3 Counter (io.pravega.shared.metrics.Counter)2