You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2016/10/14 19:22:08 UTC

[09/15] jena git commit: Correcting misuse of Context in QueryEngineHTTP

Correcting misuse of Context in QueryEngineHTTP


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/cf31d271
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/cf31d271
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/cf31d271

Branch: refs/heads/master
Commit: cf31d27147eb1653e4b0d74ac7800851d32db46c
Parents: d193bc0
Author: ajs6f <aj...@virginia.edu>
Authored: Sat Oct 8 13:15:28 2016 -0400
Committer: ajs6f <aj...@virginia.edu>
Committed: Thu Oct 13 16:09:42 2016 -0400

----------------------------------------------------------------------
 .../sparql/engine/http/QueryEngineHTTP.java     |  2 +-
 .../java/org/apache/jena/fuseki/TestAuth.java   | 52 +++++++---------
 .../java/org/apache/jena/fuseki/TestAuth.java   | 63 ++++++++------------
 3 files changed, 48 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/cf31d271/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java b/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
index d250878..75d6bad 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/engine/http/QueryEngineHTTP.java
@@ -135,7 +135,7 @@ public class QueryEngineHTTP implements QueryExecution {
         this.query = query;
         this.queryString = queryString;
         this.service = serviceURI;
-        this.context = ARQ.getContext();
+        this.context = ARQ.getContext().copy();
 
         // Apply service configuration if relevant
         applyServiceConfig(serviceURI, this);

http://git-wip-us.apache.org/repos/asf/jena/blob/cf31d271/jena-fuseki1/src/test/java/org/apache/jena/fuseki/TestAuth.java
----------------------------------------------------------------------
diff --git a/jena-fuseki1/src/test/java/org/apache/jena/fuseki/TestAuth.java b/jena-fuseki1/src/test/java/org/apache/jena/fuseki/TestAuth.java
index 00fc7cb..a2e9928 100644
--- a/jena-fuseki1/src/test/java/org/apache/jena/fuseki/TestAuth.java
+++ b/jena-fuseki1/src/test/java/org/apache/jena/fuseki/TestAuth.java
@@ -224,40 +224,30 @@ public class TestAuth {
 
     @Test
     public void query_with_auth_10() {
-        Context ctx = ARQ.getContext();
-        try {
-            QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
-
-            // Auth credentials for valid user with correct password and scoped to correct URI
-            // Provided via Service Context
-            Map<String, Context> serviceContext = new HashMap<>();
-            Context authContext = new Context();
-            authContext.put(Service.queryClient, withCreds("allowed", "password"));
-            serviceContext.put(authServiceQuery, authContext);
-            ctx.put(Service.serviceContext, serviceContext);
-            Assert.assertTrue(qe.execAsk());
-        } finally {
-            ctx.remove(Service.serviceContext);
-        }
+        QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
+
+        // Auth credentials for valid user with correct password and scoped to correct URI
+        // Provided via Service Context
+        Map<String, Context> serviceContext = new HashMap<>();
+        Context authContext = new Context();
+        authContext.put(Service.queryClient, withCreds("allowed", "password"));
+        serviceContext.put(authServiceQuery, authContext);
+        qe.getContext().put(Service.serviceContext, serviceContext);
+        Assert.assertTrue(qe.execAsk());
     }
     
     @Test
     public void query_with_auth_11() {
-        Context ctx = ARQ.getContext();
-        try {
-            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
-            // Provided via Service Context
-            Map<String, Context> serviceContext = new HashMap<>();
-            Context authContext = new Context();
-            authContext.put(Service.queryClient, withCreds(URI.create(authUrlRoot), "allowed", "password"));
-            serviceContext.put(authServiceQuery, authContext);
-            ctx.put(Service.serviceContext, serviceContext);
-            Assert.assertTrue(qe.execAsk());
-        } finally {
-            ctx.remove(Service.serviceContext);
-        }
+        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
+        // Provided via Service Context
+        Map<String, Context> serviceContext = new HashMap<>();
+        Context authContext = new Context();
+        authContext.put(Service.queryClient, withCreds(URI.create(authUrlRoot), "allowed", "password"));
+        serviceContext.put(authServiceQuery, authContext);
+        qe.getContext().put(Service.serviceContext, serviceContext);
+        Assert.assertTrue(qe.execAsk());
     }
     
     @Test
@@ -367,7 +357,7 @@ public class TestAuth {
     }
 
     @Test
-    public void update_with_auth_10() throws URISyntaxException {
+    public void update_with_auth_10() {
         UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
         UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
 

http://git-wip-us.apache.org/repos/asf/jena/blob/cf31d271/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAuth.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAuth.java b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAuth.java
index 5fc988f..1a4f517 100644
--- a/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAuth.java
+++ b/jena-fuseki2/jena-fuseki-core/src/test/java/org/apache/jena/fuseki/TestAuth.java
@@ -34,7 +34,6 @@ import org.apache.http.impl.client.BasicCredentialsProvider;
 import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.jena.atlas.logging.LogCtl ;
 import org.apache.jena.atlas.web.HttpException ;
-import org.apache.jena.query.ARQ ;
 import org.apache.jena.query.DatasetAccessor ;
 import org.apache.jena.query.DatasetAccessorFactory ;
 import org.apache.jena.query.QueryExecutionFactory ;
@@ -189,46 +188,36 @@ public class TestAuth {
 
     @Test
     public void query_with_auth_10() {
-        Context ctx = ARQ.getContext();
-        try {
-            QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
-
-            // Auth credentials for valid user with correct password and scoped
-            // to correct URI
-            // Provided via Service Context and its associated authenticator
-            Map<String, Context> serviceContext = new HashMap<>();
-            Context authContext = new Context();
-
-            HttpClient client = withBasicAuth(ANY, "allowed", "password");
-            authContext.put(Service.queryClient, client );
-            serviceContext.put(authServiceQuery, authContext);
-            ctx.put(Service.serviceContext, serviceContext);
-            Assert.assertTrue(qe.execAsk());
-        } finally {
-            ctx.remove(Service.serviceContext);
-        }
+        QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
+
+        // Auth credentials for valid user with correct password and scoped
+        // to correct URI
+        // Provided via Service Context and its associated authenticator
+        Map<String, Context> serviceContext = new HashMap<>();
+        Context authContext = new Context();
+
+        HttpClient client = withBasicAuth(ANY, "allowed", "password");
+        authContext.put(Service.queryClient, client);
+        serviceContext.put(authServiceQuery, authContext);
+        qe.getContext().put(Service.serviceContext, serviceContext);
+        Assert.assertTrue(qe.execAsk());
     }
     
     @Test
     public void query_with_auth_11() {
-        Context ctx = ARQ.getContext();
-        try {
-            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
-            // Provided via Service Context and its associated authenticator
-            Map<String, Context> serviceContext = new HashMap<>();
-            Context authContext = new Context();
-
-            HttpClient client = withBasicAuth(ANY, "allowed", "password");
-            authContext.put(Service.queryClient, client );
-            serviceContext.put(authServiceQuery, authContext);
-            ctx.put(Service.serviceContext, serviceContext);
-            Assert.assertTrue(qe.execAsk());
-        } finally {
-            ctx.remove(Service.serviceContext);
-        }
+        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
+        // Provided via Service Context and its associated authenticator
+        Map<String, Context> serviceContext = new HashMap<>();
+        Context authContext = new Context();
+
+        HttpClient client = withBasicAuth(ANY, "allowed", "password");
+        authContext.put(Service.queryClient, client);
+        serviceContext.put(authServiceQuery, authContext);
+        qe.getContext().put(Service.serviceContext, serviceContext);
+        Assert.assertTrue(qe.execAsk());
     }
     
     @Test