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