Search in sources :

Example 1 with QueryEngineHTTP

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

Example 2 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 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;
}
Also used : QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP)

Example 3 with QueryEngineHTTP

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

Example 4 with QueryEngineHTTP

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);
    }
}
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 5 with QueryEngineHTTP

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

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