Search in sources :

Example 11 with QueryEngineHTTP

use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.

the class TestAuth method query_with_auth_13.

@Test
public void query_with_auth_13() throws URISyntaxException {
    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
    qe.setClient(withBasicAuth(new AuthScope("localhost", authPort), "allowed", "password"));
    Assert.assertTrue(qe.execAsk());
}
Also used : QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) AuthScope(org.apache.http.auth.AuthScope) Test(org.junit.Test)

Example 12 with QueryEngineHTTP

use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.

the class TestAuth method query_with_auth_01.

@Test(expected = QueryExceptionHTTP.class)
public void query_with_auth_01() {
    QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
    // No auth credentials should result in an error
    qe.execAsk();
}
Also used : QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) Test(org.junit.Test)

Example 13 with QueryEngineHTTP

use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.

the class TestAuth method query_with_auth_02.

@Test(expected = QueryExceptionHTTP.class)
public void query_with_auth_02() {
    QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
    // Auth credentials for valid user with bad password
    qe.setClient(withBasicAuth(ANY, "allowed", "incorrect"));
    qe.execAsk();
}
Also used : QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) Test(org.junit.Test)

Example 14 with QueryEngineHTTP

use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.

the class TestAuth method query_with_auth_14.

@Test
public void query_with_auth_14() throws URISyntaxException {
    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
    qe.setClient(withBasicAuth(new AuthScope("localhost", authPort), "allowed", "password"));
    Assert.assertTrue(qe.execAsk());
}
Also used : QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) AuthScope(org.apache.http.auth.AuthScope) Test(org.junit.Test)

Example 15 with QueryEngineHTTP

use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.

the class TestService method query_service_context_application_02.

@SuppressWarnings("unchecked")
@Test
public void query_service_context_application_02() {
    // This test requires us to set some authentication credentials 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 {
        HttpClient testClient = HttpClients.custom().build();
        serviceContext.put(Service.queryClient, testClient);
        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.assertTrue(engine.getAllowCompression());
        Assert.assertEquals(testClient, engine.getClient());
    } finally {
        serviceContext.remove(Service.queryClient);
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) Query(org.apache.jena.query.Query) HttpClient(org.apache.http.client.HttpClient) 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