Search in sources :

Example 16 with QueryEngineHTTP

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);
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) Query(org.apache.jena.query.Query) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 17 with QueryEngineHTTP

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);
            }
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Quad(org.apache.jena.sparql.core.Quad) QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) ServerCtl.serviceQuery(org.apache.jena.fuseki.ServerCtl.serviceQuery) MediaType(org.apache.jena.atlas.web.MediaType) ServerTest(org.apache.jena.fuseki.ServerTest) Test(org.junit.Test)

Example 18 with QueryEngineHTTP

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);
}
Also used : QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) ServerCtl.serviceQuery(org.apache.jena.fuseki.ServerCtl.serviceQuery) Test(org.junit.Test)

Example 19 with QueryEngineHTTP

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);
            }
        }
    }
}
Also used : Triple(org.apache.jena.graph.Triple) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) MediaType(org.apache.jena.atlas.web.MediaType) ServerTest(org.apache.jena.fuseki.ServerTest) Test(org.junit.Test)

Example 20 with QueryEngineHTTP

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();
}
Also used : QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) AuthScope(org.apache.http.auth.AuthScope) Test(org.junit.Test)

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