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);
}
}
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);
}
}
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{}");
}
});
}
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);
}
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);
}
Aggregations