Search in sources :

Example 21 with QueryEngineHTTP

use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.

the class TestAuth method query_with_auth_11.

@Test
public void query_with_auth_11() {
    QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
    // Auth credentials for valid user with correct password and scoped
    // to base URI of the actual service URL
    // Provided via Service Context and its associated authenticator
    Map<String, Context> serviceContext = new HashMap<>();
    Context authContext = new Context();
    HttpClient client = withBasicAuth(ANY, "allowed", "password");
    authContext.put(Service.queryClient, client);
    serviceContext.put(authServiceQuery, authContext);
    qe.getContext().put(Service.serviceContext, serviceContext);
    Assert.assertTrue(qe.execAsk());
}
Also used : Context(org.apache.jena.sparql.util.Context) QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) HashMap(java.util.HashMap) HttpClient(org.apache.http.client.HttpClient) Test(org.junit.Test)

Example 22 with QueryEngineHTTP

use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.

the class TestAuth method query_with_auth_08.

@Test
public void query_with_auth_08() throws URISyntaxException {
    QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
    // Auth credentials for valid user with correct password and scoped to
    // correct URI
    qe.setClient(withBasicAuth(new AuthScope("localhost", authPort), "allowed", "password"));
    Assert.assertTrue(qe.execAsk());
}
Also used : QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) AuthScope(org.apache.http.auth.AuthScope) Test(org.junit.Test)

Example 23 with QueryEngineHTTP

use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.

the class TestAuth method query_with_auth_10.

@Test
public void query_with_auth_10() {
    QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
    // Auth credentials for valid user with correct password and scoped
    // to correct URI
    // Provided via Service Context and its associated authenticator
    Map<String, Context> serviceContext = new HashMap<>();
    Context authContext = new Context();
    HttpClient client = withBasicAuth(ANY, "allowed", "password");
    authContext.put(Service.queryClient, client);
    serviceContext.put(authServiceQuery, authContext);
    qe.getContext().put(Service.serviceContext, serviceContext);
    Assert.assertTrue(qe.execAsk());
}
Also used : Context(org.apache.jena.sparql.util.Context) QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) HashMap(java.util.HashMap) HttpClient(org.apache.http.client.HttpClient) Test(org.junit.Test)

Example 24 with QueryEngineHTTP

use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.

the class TestAuth method query_with_auth_05.

@Test
public void query_with_auth_05() {
    // Uses auth and enables compression
    QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
    qe.setAllowCompression(true);
    // Auth credentials for valid user with correct password
    qe.setClient(withBasicAuth(ANY, "allowed", "password"));
    Assert.assertTrue(qe.execAsk());
}
Also used : QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) Test(org.junit.Test)

Example 25 with QueryEngineHTTP

use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.

the class QueryExecutionFactory method sparqlService.

/** Create a QueryExecution that will access a SPARQL service over HTTP
     * @param service       URL of the remote service 
     * @param query         Query to execute
     * @param defaultGraph  URI of the default graph
     * @param client        HTTP client
     * @return QueryExecution
     */
public static QueryExecution sparqlService(String service, Query query, String defaultGraph, HttpClient client, HttpContext httpContext) {
    checkNotNull(service, "URL for service is null");
    // checkNotNull(defaultGraph, "IRI for default graph is null") ;
    checkArg(query);
    QueryEngineHTTP qe = createServiceRequest(service, query, client, httpContext);
    qe.addDefaultGraph(defaultGraph);
    return qe;
}
Also used : QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP)

Aggregations

QueryEngineHTTP (org.apache.jena.sparql.engine.http.QueryEngineHTTP)25 Test (org.junit.Test)23 HashMap (java.util.HashMap)7 Context (org.apache.jena.sparql.util.Context)7 Map (java.util.Map)5 AuthScope (org.apache.http.auth.AuthScope)5 Query (org.apache.jena.query.Query)5 HttpClient (org.apache.http.client.HttpClient)3 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 MediaType (org.apache.jena.atlas.web.MediaType)3 ServerTest (org.apache.jena.fuseki.ServerTest)3 ServerCtl.serviceQuery (org.apache.jena.fuseki.ServerCtl.serviceQuery)2 Triple (org.apache.jena.graph.Triple)1 Model (org.apache.jena.rdf.model.Model)1 Quad (org.apache.jena.sparql.core.Quad)1