jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [11/24] jena git commit: Direct setting of the "Accept" header.
Date Tue, 27 Feb 2018 23:10:31 GMT
Direct setting of the "Accept" header.

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

Branch: refs/heads/master
Commit: da1ccbc887fbcf75adad337b7727f6d99cc64640
Parents: f482aea
Author: Andy Seaborne <andy@apache.org>
Authored: Tue Feb 20 19:21:17 2018 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Tue Feb 20 20:20:10 2018 +0000

----------------------------------------------------------------------
 .../main/java/org/apache/jena/fuseki/DEF.java   |  2 +-
 .../jena/rdfconnection/RDFConnectionFuseki.java | 51 +++++++-------------
 .../jena/rdfconnection/RDFConnectionRemote.java | 46 ++++++++----------
 .../RDFConnectionRemoteBuilder.java             | 33 ++++++-------
 4 files changed, 54 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/da1ccbc8/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/DEF.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/DEF.java b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/DEF.java
index 71eaf08..05e9bf9 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/DEF.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/DEF.java
@@ -89,7 +89,7 @@ public class DEF
                                                                           ) ;
          
     // Offer for ASK
-    // This include application/xml and application/json.
+    // This includes application/xml and application/json and excludes application/sparql-results+thrift

     public static final AcceptList rsOfferBoolean      = AcceptList.create(contentTypeResultsJSON,
                                                                            contentTypeJSON,
                                                                            contentTypeTextCSV,

http://git-wip-us.apache.org/repos/asf/jena/blob/da1ccbc8/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionFuseki.java
----------------------------------------------------------------------
diff --git a/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionFuseki.java
b/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionFuseki.java
index 425450c..ece1987 100644
--- a/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionFuseki.java
+++ b/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionFuseki.java
@@ -26,11 +26,8 @@ import org.apache.jena.graph.Graph;
 import org.apache.jena.graph.Node;
 import org.apache.jena.graph.Triple;
 import org.apache.jena.query.Dataset;
-import org.apache.jena.query.Query;
 import org.apache.jena.query.QueryExecution;
-import org.apache.jena.query.QueryFactory;
 import org.apache.jena.rdf.model.Model;
-import org.apache.jena.rdfconnection.RDFConnection;
 import org.apache.jena.riot.Lang;
 import org.apache.jena.riot.RDFFormat;
 import org.apache.jena.riot.WebContent;
@@ -73,6 +70,10 @@ public class RDFConnectionFuseki extends RDFConnectionRemote {
     /** Fuseki settings */
     private static RDFConnectionRemoteBuilder setupForFuseki(RDFConnectionRemoteBuilder builder)
{
         String ctRDFThrift = Lang.RDFTHRIFT.getContentType().getContentType();
+        String acceptHeaderSPARQL = String.join("," 
+                            , ResultSetLang.SPARQLResultSetThrift.getHeaderString()
+                            , ResultSetLang.SPARQLResultSetJSON.getHeaderString()+";q=0.9"
+                            , Lang.RDFTHRIFT.getHeaderString());
         return 
             builder
                 .quadsFormat(RDFFormat.RDF_THRIFT)
@@ -81,7 +82,7 @@ public class RDFConnectionFuseki extends RDFConnectionRemote {
                 .acceptHeaderDataset(ctRDFThrift)
                 .acceptHeaderSelectQuery(ResultSetLang.SPARQLResultSetThrift.getHeaderString())
                 .acceptHeaderAskQuery(ResultSetLang.SPARQLResultSetJSON.getHeaderString())
-                .acceptHeaderGraphQuery(ResultSetLang.SPARQLResultSetThrift.getHeaderString())
+                .acceptHeaderQuery(acceptHeaderSPARQL)
                 // Create object of this class.
                 .creator((b)->fusekiMaker(b));
     }
@@ -99,18 +100,18 @@ public class RDFConnectionFuseki extends RDFConnectionRemote {
             base.destination, base.queryURL, base.updateURL, base.gspURL,
             base.outputQuads, base.outputTriples,
             base.acceptDataset, base.acceptGraph,
-            base.acceptSelectResult, base.acceptAskResult, base.acceptGraphResult);
+            base.acceptSparqlResults, base.acceptSelectResult, base.acceptAskResult);
     }
     
     protected RDFConnectionFuseki(Transactional txnLifecycle, HttpClient httpClient, HttpContext
httpContext, String destination,
                                   String queryURL, String updateURL, String gspURL, RDFFormat
outputQuads, RDFFormat outputTriples,
-                                  String acceptDataset, String acceptGraph, String acceptSelectResult,
String acceptAskResult,
-                                  String acceptGraphResult) {
+                                  String acceptDataset, String acceptGraph, 
+                                  String acceptSparqlResults, String acceptSelectResult,
String acceptAskResult) {
         super(txnLifecycle, httpClient, httpContext, 
               destination, queryURL, updateURL, gspURL,
               outputQuads, outputTriples, 
               acceptDataset, acceptGraph,
-              acceptSelectResult, acceptAskResult, acceptGraphResult);
+              acceptSparqlResults, acceptSelectResult, acceptAskResult);
     }
     
     // Fuseki specific operations.
@@ -133,41 +134,25 @@ public class RDFConnectionFuseki extends RDFConnectionRemote {
 //        }
 //    }
     
-    // Make sure all querygoes through query(String) or query(Query) 
+    // Make sure all query goes through query(String) or query(Query) 
     
     @Override
     public QueryExecution query(String queryString) {
         checkQuery();
-        
-        Query queryLocal = QueryFactory.create(queryString);
-        // XXX Kludge until QueryEngineHTTP.setAccept.
-        // XXX Accept header builder.
-        String acceptHeader = acceptSelectResult+","+acceptAskResult+";q=0.9,"+acceptGraphResult;
         return exec(()-> {
             QueryExecution qExec = new QueryEngineHTTP(svcQuery, queryString, httpClient,
httpContext);
             QueryEngineHTTP qEngine = (QueryEngineHTTP)qExec;
-            // XXX qEngine.setAccept(acceptHeader);
-            // Only one choice, not "Accept:"
-            switch ( queryLocal.getQueryType() ) {
-                case Query.QueryTypeSelect:
-                    qEngine.setSelectContentType(acceptSelectResult);
-                    break;
-                case Query.QueryTypeAsk:
-                    qEngine.setAskContentType(acceptAskResult);
-                    break;
-                case Query.QueryTypeDescribe:
-                case Query.QueryTypeConstruct:
-                    qEngine.setModelContentType(acceptGraphResult);
-                    break;
+            // We do not know the kind of query unless we parse it locally.
+            if ( acceptSparqlResults != null )
+                qEngine.setAcceptHeader(super.acceptSparqlResults);
+            else {
+                qEngine.setSelectContentType(acceptSelectResult);
+                qEngine.setAskContentType(acceptAskResult);
+                qEngine.setModelContentType(acceptGraph);
+                qEngine.setDatasetContentType(acceptDataset);
             }
             return qEngine ;
         });
-//        // XXX Better!
-//        String url = svcQuery+"?query="+queryString;
-//        // XXX Better accept.
-//        TypedInputStream in =  exec(()->HttpOp.execHttpGet(url, acceptSelectResult,
this.httpClient,this.httpContext));
-//        QueryExecution qExec = 
-//        return qExec;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/jena/blob/da1ccbc8/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionRemote.java
----------------------------------------------------------------------
diff --git a/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionRemote.java
b/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionRemote.java
index cf17c49..d0a797a 100644
--- a/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionRemote.java
+++ b/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionRemote.java
@@ -77,9 +77,9 @@ public class RDFConnectionRemote implements RDFConnection {
     protected final RDFFormat outputTriples;
     protected final String acceptGraph;
     protected final String acceptDataset;
+    protected final String acceptSparqlResults;
     protected final String acceptSelectResult;
     protected final String acceptAskResult;
-    protected final String acceptGraphResult;
     
     /** Create a {@link RDFConnectionRemoteBuilder}. */
     public static RDFConnectionRemoteBuilder create() {
@@ -159,15 +159,16 @@ public class RDFConnectionRemote implements RDFConnection {
         this(null, httpClient, null, destination, sQuery, sUpdate, sGSP,
             RDFFormat.NQUADS, RDFFormat.NTRIPLES,
             WebContent.defaultGraphAcceptHeader, WebContent.defaultDatasetAcceptHeader,
-            QueryEngineHTTP.defaultSelectHeader(), QueryEngineHTTP.defaultAskHeader(), QueryEngineHTTP.defaultConstructHeader()
-            );
+            null,
+            QueryEngineHTTP.defaultSelectHeader(), QueryEngineHTTP.defaultAskHeader());
     }
 
     // Used by the builder.
     protected RDFConnectionRemote(Transactional txnLifecycle, HttpClient httpClient, HttpContext
httpContext, String destination,
                                    String queryURL, String updateURL, String gspURL, RDFFormat
outputQuads, RDFFormat outputTriples,
-                                   String acceptDataset, String acceptGraph, String acceptSelectResult,
String acceptAskResult,
-                                   String acceptGraphResult) {
+                                   String acceptDataset, String acceptGraph,
+                                   String acceptSparqlResults,
+                                   String acceptSelectResult, String acceptAskResult) {
         this.httpClient = httpClient;
         this.httpContext = httpContext;
         this.destination = destination;
@@ -181,9 +182,9 @@ public class RDFConnectionRemote implements RDFConnection {
         this.outputTriples = outputTriples;
         this.acceptDataset = acceptDataset;
         this.acceptGraph = acceptGraph;
+        this.acceptSparqlResults = acceptSparqlResults;
         this.acceptSelectResult = acceptSelectResult;
         this.acceptAskResult = acceptAskResult;
-        this.acceptGraphResult = acceptGraphResult;
     }
 
     /** Return the {@link HttpClient} in-use. */ 
@@ -204,32 +205,23 @@ public class RDFConnectionRemote implements RDFConnection {
     @Override
     public QueryExecution query(Query query) {
         checkQuery();
-        // XXX ResultSetFormat
-        
-        
-        
         return exec(()-> {
             QueryExecution qExec = QueryExecutionFactory.sparqlService(svcQuery, query, this.httpClient,
this.httpContext);
             QueryEngineHTTP qEngine = (QueryEngineHTTP)qExec;
-            
-            // Set general HTTP header.
-            
-//            // Only one choice, not "Accept:"
-//            switch ( query.getQueryType() ) {
-//                case Query.QueryTypeSelect:
-//                    qEngine.setSelectContentType("");
-//                    break;
-//                case Query.QueryTypeAsk:
-//                    qEngine.setAskContentType("");
-//                    break;
-//                case Query.QueryTypeDescribe:
-//                case Query.QueryTypeConstruct:
-//                    qEngine.setModelContentType("");
-//                    break;
-//            }
+            if ( acceptSparqlResults != null )
+                qEngine.setAcceptHeader(acceptSparqlResults);
+            else {
+                if ( query.isSelectType() && acceptSelectResult != null )
+                    qEngine.setAcceptHeader(acceptSelectResult);
+                if ( query.isAskType() && acceptAskResult != null )
+                    qEngine.setAcceptHeader(acceptAskResult);
+                if ( ( query.isConstructType() || query.isDescribeType() ) && acceptGraph
!= null )
+                    qEngine.setAcceptHeader(acceptGraph);
+                if ( query.isConstructQuad() )
+                    qEngine.setDatasetContentType(acceptDataset);
+            }
             return qExec ;
         });
-        
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/jena/blob/da1ccbc8/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionRemoteBuilder.java
----------------------------------------------------------------------
diff --git a/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionRemoteBuilder.java
b/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionRemoteBuilder.java
index e77e738..3b5de7f 100644
--- a/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionRemoteBuilder.java
+++ b/jena-rdfconnection/src/main/java/org/apache/jena/rdfconnection/RDFConnectionRemoteBuilder.java
@@ -25,7 +25,6 @@ import java.util.function.Function;
 
 import org.apache.http.client.HttpClient;
 import org.apache.http.protocol.HttpContext;
-import org.apache.jena.rdfconnection.RDFConnection;
 import org.apache.jena.riot.*;
 import org.apache.jena.sparql.core.Transactional;
 import org.apache.jena.sparql.core.TransactionalLock;
@@ -56,7 +55,8 @@ public class RDFConnectionRemoteBuilder {
     
     protected String        acceptSelectResult = QueryEngineHTTP.defaultSelectHeader();
     protected String        acceptAskResult    = QueryEngineHTTP.defaultAskHeader();
-    protected String        acceptGraphResult  = QueryEngineHTTP.defaultConstructHeader();
+    // All-purpose head that works for any query type (but is quite long!)
+    protected String        acceptSparqlResults = null;
 
     RDFConnectionRemoteBuilder() { 
         // Default settings are the meber declarations.
@@ -81,7 +81,6 @@ public class RDFConnectionRemoteBuilder {
         
         acceptSelectResult  = base.acceptSelectResult;
         acceptAskResult     = base.acceptAskResult;
-        acceptGraphResult   = base.acceptGraphResult;
     }
     
     /** URL of the remote SPARQL endpoint.
@@ -235,7 +234,7 @@ public class RDFConnectionRemoteBuilder {
         this.acceptGraph = acceptGraph;
         return this;
     }
-
+    
     /** Set the HTTP {@code Accept:} header used to fetch RDF datasets using HTTP GET operations.
*/ 
     public RDFConnectionRemoteBuilder acceptHeaderDataset(String acceptDataset) {
         this.acceptDataset = acceptDataset;
@@ -254,16 +253,11 @@ public class RDFConnectionRemoteBuilder {
         return this;
     }
 
-    /** Set the HTTP {@code Accept:} header used to when making a SPARQL Protocol CONSTRUCT
or DESCRIBE query. */ 
-    public RDFConnectionRemoteBuilder acceptHeaderGraphQuery(String acceptGraphResultHeader)
{
-        this.acceptGraphResult = acceptGraphResultHeader;
-        return this;
-    }
-
-    // XXX Alternative:
-    /** Set the HTTP {@code Accept:} header used to when making a SPARQL Protocol query.
*/ 
-    public RDFConnectionRemoteBuilder acceptHeaderQuery(String acceptHeaderQuery) {
-        System.err.println("NOT YET IMPLEMENTED");
+    /** Set the HTTP {@code Accept:} header used to when making a 
+     * SPARQL Protocol query if no query type specific setting available.
+     */ 
+    public RDFConnectionRemoteBuilder acceptHeaderQuery(String acceptHeader) {
+        this.acceptSparqlResults = acceptHeader;
         return this;
     }
 
@@ -295,8 +289,13 @@ public class RDFConnectionRemoteBuilder {
         updateURL = LibRDFConn.formServiceURL(destination, sUpdate);
         gspURL = LibRDFConn.formServiceURL(destination, sGSP);
         
-        // XXX Sort out SPARQL Accept headers.
-        
+//        if ( acceptSparqlResults == null ) {
+//            if ( acceptSelectResult != acceptAskResult )
+//                acceptSparqlResults = String.join(",", acceptSelectResult, acceptAskResult,
acceptGraphResult);
+//            else
+//                acceptSparqlResults = String.join(",", acceptSelectResult, acceptGraphResult);
+//        }
+//        
         return maker.apply(this);
     }
     
@@ -305,6 +304,6 @@ public class RDFConnectionRemoteBuilder {
                                         destination, queryURL, updateURL, gspURL,
                                         outputQuads, outputTriples,
                                         acceptDataset, acceptGraph,
-                                        acceptSelectResult, acceptAskResult, acceptGraphResult);
+                                        acceptSparqlResults, acceptSelectResult, acceptAskResult);
     }
 }
\ No newline at end of file


Mime
View raw message