use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.
the class TestAuth method query_with_auth_12.
@Test
public void query_with_auth_12() {
ARQ.getContext().remove(Service.serviceContext);
QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
// Auth credentials for valid user with correct password
qe.setClient(withCreds("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 defaultGraphURIs List of URIs to make up the default graph
* @param namedGraphURIs List of URIs to make up the named graphs
* @param client HTTP client
* @param httpContext HTTP Context
* @return QueryExecution
*/
public static QueryExecution sparqlService(String service, Query query, List<String> defaultGraphURIs, List<String> namedGraphURIs, HttpClient client, HttpContext httpContext) {
checkNotNull(service, "URL for service is null");
// checkNotNull(defaultGraphURIs, "List of default graph URIs is null") ;
// checkNotNull(namedGraphURIs, "List of named graph URIs is null") ;
checkArg(query);
QueryEngineHTTP qe = createServiceRequest(service, query, client);
if (defaultGraphURIs != null)
qe.setDefaultGraphURIs(defaultGraphURIs);
if (namedGraphURIs != null)
qe.setNamedGraphURIs(namedGraphURIs);
return qe;
}
use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.
the class TestQuery method query_describe_conneg.
@Test
public void query_describe_conneg() throws IOException {
try (CloseableHttpClient client = HttpOp.createPoolingHttpClient()) {
String query = "DESCRIBE ?s WHERE {?s ?p ?o}";
for (MediaType type : rdfOfferTest.entries()) {
String contentType = type.toHeaderString();
try (QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery(), query)) {
qExec.setModelContentType(contentType);
qExec.setClient(client);
Model m = qExec.execDescribe();
String x = qExec.getHttpResponseContentType();
assertEquals(contentType, x);
assertFalse(m.isEmpty());
}
}
}
}
use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.
the class TestService method query_service_context_application_03.
@SuppressWarnings("unchecked")
@Test
public void query_service_context_application_03() {
// This test requires us to set some timeouts for the service
Map<String, Context> serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
if (serviceContextMap == null) {
ARQ.getContext().put(Service.serviceContext, new HashMap<String, Context>());
serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
}
if (serviceContextMap.get(SERVICE) == null) {
serviceContextMap.put(SERVICE, new Context(ARQ.getContext()));
}
Context serviceContext = serviceContextMap.get(SERVICE);
try {
serviceContext.put(Service.queryTimeout, "10");
Query q = QueryFactory.create("ASK { }");
QueryEngineHTTP engine = QueryExecutionFactory.createServiceRequest(SERVICE, q);
Assert.assertNotNull(engine);
// Check that no settings were changed
Assert.assertEquals(-1, engine.getTimeout1());
Assert.assertEquals(10, engine.getTimeout2());
Assert.assertTrue(engine.getAllowCompression());
Assert.assertNull(engine.getClient());
} finally {
serviceContext.remove(Service.queryTimeout);
}
}
use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.
the class TestService method query_service_context_application_04.
@SuppressWarnings("unchecked")
@Test
public void query_service_context_application_04() {
// This test requires us to set some timeouts for the service
Map<String, Context> serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
if (serviceContextMap == null) {
ARQ.getContext().put(Service.serviceContext, new HashMap<String, Context>());
serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
}
if (serviceContextMap.get(SERVICE) == null) {
serviceContextMap.put(SERVICE, new Context(ARQ.getContext()));
}
Context serviceContext = serviceContextMap.get(SERVICE);
try {
serviceContext.put(Service.queryTimeout, "10,20");
Query q = QueryFactory.create("ASK { }");
QueryEngineHTTP engine = QueryExecutionFactory.createServiceRequest(SERVICE, q);
Assert.assertNotNull(engine);
// Check that no settings were changed
Assert.assertEquals(20, engine.getTimeout1());
Assert.assertEquals(10, engine.getTimeout2());
Assert.assertTrue(engine.getAllowCompression());
Assert.assertNull(engine.getClient());
} finally {
serviceContext.remove(Service.queryTimeout);
}
}
Aggregations