Author: rvesse
Date: Wed Jul 3 16:48:35 2013
New Revision: 1499471
URL: http://svn.apache.org/r1499471
Log:
Add overloads for QueryExecutionFactory.sparqlService() that take
HttpAuthenticator (JENA-480)
Modified:
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/query/QueryExecutionFactory.java
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/http/QueryEngineHTTP.java
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemote.java
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemoteForm.java
Modified:
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/query/QueryExecutionFactory.java
URL:
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/query/QueryExecutionFactory.java?rev=1499471&r1=1499470&r2=1499471&view=diff
==============================================================================
---
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/query/QueryExecutionFactory.java
(original)
+++
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/query/QueryExecutionFactory.java
Wed Jul 3 16:48:35 2013
@@ -20,6 +20,7 @@ package com.hp.hpl.jena.query;
import java.util.List ;
import org.apache.jena.atlas.logging.Log ;
+import org.apache.jena.atlas.web.auth.HttpAuthenticator;
import com.hp.hpl.jena.rdf.model.Model ;
import com.hp.hpl.jena.sparql.core.DatasetGraph ;
@@ -339,29 +340,50 @@ public class QueryExecutionFactory
* @param query Query string to execute
* @return QueryExecution
*/
-
static public QueryExecution sparqlService(String service, String query)
{
+ return sparqlService(service, query, (HttpAuthenticator)null);
+ }
+
+ /** Create a QueryExecution that will access a SPARQL service over HTTP
+ * @param service URL of the remote service
+ * @param query Query string to execute
+ * @param authenticator HTTP Authenticator
+ * @return QueryExecution
+ */
+ static public QueryExecution sparqlService(String service, String query,
HttpAuthenticator authenticator)
+ {
checkNotNull(service, "URL for service is null") ;
checkArg(query) ;
- return sparqlService(service, QueryFactory.create(query)) ;
+ return sparqlService(service, QueryFactory.create(query),
authenticator) ;
}
-
+
/** Create a QueryExecution that will access a SPARQL service over HTTP
* @param service URL of the remote service
* @param query Query string to execute
* @param defaultGraph URI of the default graph
* @return QueryExecution
*/
-
static public QueryExecution sparqlService(String service, String query,
String defaultGraph)
{
+ return sparqlService(service, query, defaultGraph, null);
+ }
+
+ /** Create a QueryExecution that will access a SPARQL service over HTTP
+ * @param service URL of the remote service
+ * @param query Query string to execute
+ * @param defaultGraph URI of the default graph
+ * @param authenticator HTTP Authenticator
+ * @return QueryExecution
+ */
+ static public QueryExecution sparqlService(String service, String query,
String defaultGraph, HttpAuthenticator authenticator)
+ {
checkNotNull(service, "URL for service is null") ;
//checkNotNull(defaultGraph, "IRI for default graph is null") ;
checkArg(query) ;
- return sparqlService(service, QueryFactory.create(query),
defaultGraph) ;
+ return sparqlService(service, QueryFactory.create(query),
defaultGraph, authenticator) ;
}
-
+
/** Create a QueryExecution that will access a SPARQL service over HTTP
* @param service URL of the remote service
* @param query Query string to execute
@@ -371,11 +393,24 @@ public class QueryExecutionFactory
*/
static public QueryExecution sparqlService(String service, String query,
List<String> defaultGraphURIs, List<String> namedGraphURIs)
{
+ return sparqlService(service, query, defaultGraphURIs, namedGraphURIs,
null);
+ }
+
+ /** Create a QueryExecution that will access a SPARQL service over HTTP
+ * @param service URL of the remote service
+ * @param query Query string 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 authenticator HTTP Authenticator
+ * @return QueryExecution
+ */
+ static public QueryExecution sparqlService(String service, String query,
List<String> defaultGraphURIs, List<String> namedGraphURIs, HttpAuthenticator
authenticator)
+ {
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) ;
- return sparqlService(service, QueryFactory.create(query),
defaultGraphURIs, namedGraphURIs) ;
+ return sparqlService(service, QueryFactory.create(query),
defaultGraphURIs, namedGraphURIs, authenticator) ;
}
/** Create a QueryExecution that will access a SPARQL service over HTTP
@@ -383,14 +418,24 @@ public class QueryExecutionFactory
* @param query Query to execute
* @return QueryExecution
*/
-
static public QueryExecution sparqlService(String service, Query query)
{
+ return sparqlService(service, query, (HttpAuthenticator)null);
+ }
+
+ /** Create a QueryExecution that will access a SPARQL service over HTTP
+ * @param service URL of the remote service
+ * @param query Query to execute
+ * @param authenticator HTTP Authenticator
+ * @return QueryExecution
+ */
+ static public QueryExecution sparqlService(String service, Query query,
HttpAuthenticator authenticator)
+ {
checkNotNull(service, "URL for service is null") ;
checkArg(query) ;
- return createServiceRequest(service, query) ;
+ return createServiceRequest(service, query, authenticator) ;
}
-
+
/** Create a QueryExecution that will access a SPARQL service over HTTP
* @param service URL of the remote service
* @param query Query to execute
@@ -400,42 +445,82 @@ public class QueryExecutionFactory
*/
static public QueryExecution sparqlService(String service, Query query,
List<String> defaultGraphURIs, List<String> namedGraphURIs)
{
+ return sparqlService(service, query, defaultGraphURIs, namedGraphURIs,
null);
+ }
+
+ /** 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 authenticator HTTP Authenticator
+ * @return QueryExecution
+ */
+ static public QueryExecution sparqlService(String service, Query query,
List<String> defaultGraphURIs, List<String> namedGraphURIs, HttpAuthenticator
authenticator)
+ {
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) ;
+ QueryEngineHTTP qe = createServiceRequest(service, query,
authenticator) ;
if ( defaultGraphURIs != null )
qe.setDefaultGraphURIs(defaultGraphURIs) ;
if ( namedGraphURIs != null )
qe.setNamedGraphURIs(namedGraphURIs) ;
return qe ;
}
-
+
/** Create a QueryExecution that will access a SPARQL service over HTTP
* @param service URL of the remote service
* @param query Query to execute
* @param defaultGraph URI of the default graph
* @return QueryExecution
*/
-
static public QueryExecution sparqlService(String service, Query query,
String defaultGraph)
{
+ return sparqlService(service, query, defaultGraph, null);
+ }
+
+ /** Create a QueryExecution that will access a SPARQL service over HTTP
+ * @param service URL of the remote service
+ * @param query Query to execute
+ * @param defaultGraph URI of the default graph
+ * @param authenticator HTTP Authenticator
+ * @return QueryExecution
+ */
+ static public QueryExecution sparqlService(String service, Query query,
String defaultGraph, HttpAuthenticator authenticator)
+ {
checkNotNull(service, "URL for service is null") ;
//checkNotNull(defaultGraph, "IRI for default graph is null") ;
checkArg(query) ;
- QueryEngineHTTP qe = createServiceRequest(service, query) ;
+ QueryEngineHTTP qe = createServiceRequest(service, query,
authenticator) ;
qe.addDefaultGraph(defaultGraph) ;
return qe ;
}
/** Create a service request for remote execution over HTTP. The returned
class,
* {@link QueryEngineHTTP},
- * allows various HTTP specific paramters to be set.
+ * allows various HTTP specific parameters to be set.
+ * @param service Endpoint URL
+ * @param query Query
+ * @return Remote Query Engine
*/
static public QueryEngineHTTP createServiceRequest(String service, Query
query)
{
- QueryEngineHTTP qe = new QueryEngineHTTP(service, query) ;
+ return createServiceRequest(service, query, null);
+ }
+
+ /** Create a service request for remote execution over HTTP. The returned
class,
+ * {@link QueryEngineHTTP},
+ * allows various HTTP specific parameters to be set.
+ * @param service Endpoint URL
+ * @param query Query
+ * @param authenticator HTTP Authenticator
+ * @return Remote Query Engine
+ */
+ static public QueryEngineHTTP createServiceRequest(String service, Query
query, HttpAuthenticator authenticator)
+ {
+ QueryEngineHTTP qe = new QueryEngineHTTP(service, query,
authenticator) ;
return qe ;
}
Modified:
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/http/QueryEngineHTTP.java
URL:
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/http/QueryEngineHTTP.java?rev=1499471&r1=1499470&r2=1499471&view=diff
==============================================================================
---
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/http/QueryEngineHTTP.java
(original)
+++
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/http/QueryEngineHTTP.java
Wed Jul 3 16:48:35 2013
@@ -85,8 +85,14 @@ public class QueryEngineHTTP implements
private String selectContentType = WebContent.contentTypeResultsXML;
private String askContentType = WebContent.contentTypeResultsXML;
private String modelContentType = WebContent.contentTypeRDFXML;
+ /**
+ * Supported content types for SELECT queries
+ */
public static String[] supportedSelectContentTypes = new String[] {
WebContent.contentTypeResultsXML,
WebContent.contentTypeResultsJSON, WebContent.contentTypeTextTSV,
WebContent.contentTypeTextCSV };
+ /**
+ * Supported content types for ASK queries
+ */
public static String[] supportedAskContentTypes = new String[] {
WebContent.contentTypeResultsXML,
WebContent.contentTypeJSON, WebContent.contentTypeTextTSV,
WebContent.contentTypeTextCSV };
@@ -97,12 +103,24 @@ public class QueryEngineHTTP implements
public QueryEngineHTTP(String serviceURI, Query query) {
this(serviceURI, query, query.toString());
}
+
+ public QueryEngineHTTP(String serviceURI, Query query, HttpAuthenticator
authenticator) {
+ this(serviceURI, query, query.toString(), authenticator);
+ }
public QueryEngineHTTP(String serviceURI, String queryString) {
this(serviceURI, null, queryString);
}
-
+
+ public QueryEngineHTTP(String serviceURI, String queryString,
HttpAuthenticator authenticator) {
+ this(serviceURI, null, queryString, authenticator);
+ }
+
private QueryEngineHTTP(String serviceURI, Query query, String
queryString) {
+ this(serviceURI, query, queryString, null);
+ }
+
+ private QueryEngineHTTP(String serviceURI, Query query, String
queryString, HttpAuthenticator authenticator) {
this.query = query;
this.queryString = queryString;
this.service = serviceURI;
@@ -111,6 +129,12 @@ public class QueryEngineHTTP implements
// Apply service configuration if relevant
QueryEngineHTTP.applyServiceConfig(serviceURI, this);
+
+ // Don't want to overwrite credentials we may have picked up from
+ // service context in the parent constructor if the specified
+ // authenticator is null
+ if (authenticator != null)
+ this.setAuthenticator(authenticator);
}
/**
Modified:
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemote.java
URL:
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemote.java?rev=1499471&r1=1499470&r2=1499471&view=diff
==============================================================================
---
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemote.java
(original)
+++
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemote.java
Wed Jul 3 16:48:35 2013
@@ -53,7 +53,11 @@ public class UpdateProcessRemote extends
public UpdateProcessRemote(UpdateRequest request, String endpoint, Context
context, HttpAuthenticator authenticator)
{
this(request, endpoint, context);
- this.setAuthenticator(authenticator);
+ // Don't want to overwrite credentials we may have picked up from
+ // service context in the parent constructor if the specified
+ // authenticator is null
+ if (authenticator != null)
+ this.setAuthenticator(authenticator);
}
@Override
Modified:
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemoteForm.java
URL:
http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemoteForm.java?rev=1499471&r1=1499470&r2=1499471&view=diff
==============================================================================
---
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemoteForm.java
(original)
+++
jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/UpdateProcessRemoteForm.java
Wed Jul 3 16:48:35 2013
@@ -19,61 +19,73 @@
package com.hp.hpl.jena.sparql.modify;
import org.apache.jena.atlas.web.auth.HttpAuthenticator;
-import org.apache.jena.riot.web.HttpOp ;
-import org.apache.jena.riot.web.HttpResponseLib ;
+import org.apache.jena.riot.web.HttpOp;
+import org.apache.jena.riot.web.HttpResponseLib;
-import com.hp.hpl.jena.sparql.ARQException ;
-import com.hp.hpl.jena.sparql.engine.http.HttpParams ;
-import com.hp.hpl.jena.sparql.engine.http.Params ;
-import com.hp.hpl.jena.sparql.util.Context ;
-import com.hp.hpl.jena.update.UpdateProcessor ;
-import com.hp.hpl.jena.update.UpdateRequest ;
+import com.hp.hpl.jena.sparql.ARQException;
+import com.hp.hpl.jena.sparql.engine.http.HttpParams;
+import com.hp.hpl.jena.sparql.engine.http.Params;
+import com.hp.hpl.jena.sparql.util.Context;
+import com.hp.hpl.jena.update.UpdateProcessor;
+import com.hp.hpl.jena.update.UpdateRequest;
/**
- * UpdateProcess that send the request to a SPARQL endpoint by using an HTML
form and POST
- * Use of application/sparql-update via @link{UpdateProcessRemote} is
preferred.
+ * UpdateProcess that send the request to a SPARQL endpoint by using an HTML
+ * form and POST Use of application/sparql-update via
@link{UpdateProcessRemote}
+ * is preferred.
*/
-public class UpdateProcessRemoteForm extends UpdateProcessRemoteBase
implements UpdateProcessor
-{
-
+public class UpdateProcessRemoteForm extends UpdateProcessRemoteBase
implements UpdateProcessor {
+
/**
- * Creates a new remote update processor that uses the form URL encoded
submission method
- * @param request Update request
- * @param endpoint Update endpoint
- * @param context Context
+ * Creates a new remote update processor that uses the form URL encoded
+ * submission method
+ *
+ * @param request
+ * Update request
+ * @param endpoint
+ * Update endpoint
+ * @param context
+ * Context
*/
- public UpdateProcessRemoteForm(UpdateRequest request , String endpoint,
Context context )
- {
+ public UpdateProcessRemoteForm(UpdateRequest request, String endpoint,
Context context) {
super(request, endpoint, context);
}
-
+
/**
- * Creates a new remote update processor that uses the form URL encoded
submission method
- * @param request Update request
- * @param endpoint Update endpoint
- * @param context Context
- * @param authenticator HTTP Authenticator
+ * Creates a new remote update processor that uses the form URL encoded
+ * submission method
+ *
+ * @param request
+ * Update request
+ * @param endpoint
+ * Update endpoint
+ * @param context
+ * Context
+ * @param authenticator
+ * HTTP Authenticator
*/
- public UpdateProcessRemoteForm(UpdateRequest request , String endpoint,
Context context, HttpAuthenticator authenticator)
- {
+ public UpdateProcessRemoteForm(UpdateRequest request, String endpoint,
Context context, HttpAuthenticator authenticator) {
this(request, endpoint, context);
- this.setAuthenticator(authenticator);
+ // Don't want to overwrite credentials we may have picked up from
+ // service context in the parent constructor if the specified
+ // authenticator is null
+ if (authenticator != null)
+ this.setAuthenticator(authenticator);
}
@Override
- public void execute()
- {
+ public void execute() {
// Validation
- if ( this.getEndpoint() == null )
- throw new ARQException("Null endpoint for remote update by form") ;
- if ( this.getUpdateRequest() == null )
- throw new ARQException("Null update request for remote update") ;
-
+ if (this.getEndpoint() == null)
+ throw new ARQException("Null endpoint for remote update by form");
+ if (this.getUpdateRequest() == null)
+ throw new ARQException("Null update request for remote update");
+
// Execution
- String reqStr = this.getUpdateRequest().toString() ;
+ String reqStr = this.getUpdateRequest().toString();
Params ps = new Params(this.getParams());
ps.addParam(HttpParams.pUpdate, reqStr);
- HttpOp.execHttpPostForm(this.getEndpoint(), ps, null,
HttpResponseLib.nullResponse, null, getHttpContext(), getAuthenticator()) ;
+ HttpOp.execHttpPostForm(this.getEndpoint(), ps, null,
HttpResponseLib.nullResponse, null, getHttpContext(),
+ getAuthenticator());
}
}
-