use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.
the class TestService method query_service_context_application_05.
@SuppressWarnings("unchecked")
@Test
public void query_service_context_application_05() {
// This test requires us to set that GZip and Deflate are permitted
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.queryCompression, false);
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(-1, engine.getTimeout2());
Assert.assertFalse(engine.getAllowCompression());
Assert.assertNull(engine.getClient());
} finally {
serviceContext.remove(Service.queryCompression);
}
}
use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.
the class TestQuery method query_construct_quad_conneg.
@Test
public void query_construct_quad_conneg() throws IOException {
try (CloseableHttpClient client = HttpOp.createPoolingHttpClient()) {
String queryString = " CONSTRUCT { GRAPH ?g {?s ?p ?o} } WHERE { GRAPH ?g {?s ?p ?o}}";
Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
for (MediaType type : quadsOfferTest.entries()) {
String contentType = type.toHeaderString();
try (QueryEngineHTTP qExec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(serviceQuery(), query)) {
qExec.setDatasetContentType(contentType);
qExec.setClient(client);
Iterator<Quad> iter = qExec.execConstructQuads();
assertTrue(iter.hasNext());
String x = qExec.getHttpResponseContentType();
assertEquals(contentType, x);
}
}
}
}
use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.
the class TestSPARQLProtocol method query_02.
@Test
public void query_02() {
Query query = QueryFactory.create("SELECT * { ?s ?p ?o }");
QueryEngineHTTP engine = QueryExecutionFactory.createServiceRequest(serviceQuery(), query);
engine.setSelectContentType(WebContent.contentTypeResultsJSON);
ResultSet rs = engine.execSelect();
int x = ResultSetFormatter.consume(rs);
assertTrue(x != 0);
}
use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.
the class TestQuery method query_construct_conneg.
// Conneg tests:
// These use independent connection pooling.
// Sharing pooling too much leads to lock up if the list is long (contentTypeTriXxml seems significant)
// Hence: try (CloseableHttpClient client = HttpOp.createPoolingHttpClient()) { ... qExec.setClient(client); ... }
@Test
public void query_construct_conneg() throws IOException {
try (CloseableHttpClient client = HttpOp.createPoolingHttpClient()) {
String query = " CONSTRUCT {?s ?p ?o} 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);
Iterator<Triple> iter = qExec.execConstructTriples();
assertTrue(iter.hasNext());
String x = qExec.getHttpResponseContentType();
assertEquals(contentType, x);
}
}
}
}
use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.
the class TestAuth method query_with_auth_07.
@Test(expected = QueryExceptionHTTP.class)
public void query_with_auth_07() throws URISyntaxException {
QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
// Auth credentials for valid user with correct password but scoped to
// wrong URI
qe.setClient(withBasicAuth(new AuthScope("example", authPort), "allowed", "password"));
qe.execAsk();
}
Aggregations