Search in sources :

Example 6 with QueryExecutionHTTP

use of org.apache.jena.sparql.exec.http.QueryExecutionHTTP in project jena by apache.

the class TestAuthQuery_JDK method query_authenv_02_prefix_good.

@Test
public void query_authenv_02_prefix_good() {
    QueryExecutionHTTP qe = QueryExecutionHTTP.create().endpoint(databaseURL()).query("ASK { }").build();
    // Dataset URL.
    String dsURL = serverURL;
    URI uri = URI.create(dsURL);
    AuthEnv.get().registerUsernamePassword(uri, "allowed", "password");
    try {
        Assert.assertTrue(qe.execAsk());
    } finally {
        AuthEnv.get().unregisterUsernamePassword(uri);
    }
}
Also used : QueryExecutionHTTP(org.apache.jena.sparql.exec.http.QueryExecutionHTTP) URI(java.net.URI) Test(org.junit.Test) HttpTest(org.apache.jena.fuseki.test.HttpTest)

Example 7 with QueryExecutionHTTP

use of org.apache.jena.sparql.exec.http.QueryExecutionHTTP in project jena by apache.

the class TestAuthQuery_JDK method query_authenv_03_bad_endpoint.

@Test
public void query_authenv_03_bad_endpoint() {
    QueryExecutionHTTP qe = QueryExecutionHTTP.create().endpoint(databaseURL()).query("ASK { }").build();
    // Wrong registration
    String dsURL = serverURL + "anotherPlace";
    URI uri = URI.create(dsURL);
    AuthEnv.get().registerUsernamePassword(uri, "allowed", "password");
    try {
        expectQuery401(() -> qe.execAsk());
    } finally {
        AuthEnv.get().unregisterUsernamePassword(uri);
    }
}
Also used : QueryExecutionHTTP(org.apache.jena.sparql.exec.http.QueryExecutionHTTP) URI(java.net.URI) Test(org.junit.Test) HttpTest(org.apache.jena.fuseki.test.HttpTest)

Example 8 with QueryExecutionHTTP

use of org.apache.jena.sparql.exec.http.QueryExecutionHTTP in project jena by apache.

the class rsparql method exec.

@Override
protected void exec() {
    Query query = modQuery.getQuery();
    try {
        String serviceURL = modRemote.getServiceURL();
        QuerySendMode sendMode = modRemote.usePost() ? QuerySendMode.asPost : QuerySendMode.systemDefault;
        QueryExecutionHTTP qe = QueryExecutionHTTPBuilder.create().endpoint(serviceURL).query(query).sendMode(sendMode).build();
        QueryExecUtils.executeQuery(query, qe, modResults.getResultsFormat());
    } catch (QueryExceptionHTTP ex) {
        throw new CmdException("HTTP Exception", ex);
    } catch (Exception ex) {
        System.out.flush();
        ex.printStackTrace(System.err);
    }
}
Also used : Query(org.apache.jena.query.Query) CmdException(org.apache.jena.cmd.CmdException) QueryExecutionHTTP(org.apache.jena.sparql.exec.http.QueryExecutionHTTP) QueryExceptionHTTP(org.apache.jena.sparql.engine.http.QueryExceptionHTTP) QuerySendMode(org.apache.jena.sparql.exec.http.QuerySendMode) CmdException(org.apache.jena.cmd.CmdException)

Example 9 with QueryExecutionHTTP

use of org.apache.jena.sparql.exec.http.QueryExecutionHTTP in project jena by apache.

the class TestWebappAuthQuery_JDK method query_authenv_03_bad_endpoint.

@Test
public void query_authenv_03_bad_endpoint() {
    QueryExecutionHTTP qe = QueryExecutionHTTP.create().endpoint(authServiceQuery).query("ASK { }").build();
    // Wrong registration
    String dsURL = "http://localhost:" + authPort + "/anotherPlace";
    URI uri = URI.create(dsURL);
    AuthEnv.get().registerUsernamePassword(uri, "allowed", "password");
    try {
        HttpTest.expectQuery401(() -> qe.execAsk());
    } finally {
        AuthEnv.get().unregisterUsernamePassword(uri);
    }
}
Also used : QueryExecutionHTTP(org.apache.jena.sparql.exec.http.QueryExecutionHTTP) URI(java.net.URI) Test(org.junit.Test) HttpTest(org.apache.jena.fuseki.test.HttpTest)

Example 10 with QueryExecutionHTTP

use of org.apache.jena.sparql.exec.http.QueryExecutionHTTP in project jena by apache.

the class TestWebappAuthQuery_JDK method query_auth_jdk_01_no_auth.

@Test
public void query_auth_jdk_01_no_auth() {
    QueryExecutionHTTP qe = QueryExecutionHTTP.create().endpoint(authServiceQuery).query("ASK { }").build();
    // No auth credentials should result in an error
    HttpTest.expectQuery401(() -> qe.execAsk());
}
Also used : QueryExecutionHTTP(org.apache.jena.sparql.exec.http.QueryExecutionHTTP) Test(org.junit.Test) HttpTest(org.apache.jena.fuseki.test.HttpTest)

Aggregations

QueryExecutionHTTP (org.apache.jena.sparql.exec.http.QueryExecutionHTTP)13 HttpTest (org.apache.jena.fuseki.test.HttpTest)12 Test (org.junit.Test)12 URI (java.net.URI)6 CmdException (org.apache.jena.cmd.CmdException)1 Query (org.apache.jena.query.Query)1 QueryExceptionHTTP (org.apache.jena.sparql.engine.http.QueryExceptionHTTP)1 QuerySendMode (org.apache.jena.sparql.exec.http.QuerySendMode)1