Permalink
Browse files

Added an option to pass HTTP auth user and password details for sparq…

…l.remote()
  • Loading branch information...
1 parent f76ad3d commit c5bc0010901701ef17359235a3a560c0de62e873 @egonw committed Sep 24, 2011
@@ -105,7 +105,8 @@ public static StringMatrix sparql(Model model, String queryString) throws Except
return table;
}
- public static StringMatrix sparqlRemote(String endpoint, String queryString) throws Exception {
+ public static StringMatrix sparqlRemote(String endpoint, String queryString)
+ throws Exception {
StringMatrix table = null;
Query query = QueryFactory.create(queryString);
QueryEngineHTTP qexec = (QueryEngineHTTP)QueryExecutionFactory.sparqlService(endpoint, query);
@@ -120,6 +121,25 @@ public static StringMatrix sparqlRemote(String endpoint, String queryString) thr
return table;
}
+ public static StringMatrix sparqlRemote(String endpoint, String queryString, String user, String password)
+ throws Exception {
+ StringMatrix table = null;
+ Query query = QueryFactory.create(queryString);
+ QueryEngineHTTP qexec = (QueryEngineHTTP)QueryExecutionFactory.sparqlService(endpoint, query);
+ if (user != null) {
+ qexec.setBasicAuthentication("" + user, ("" + password).toCharArray());
+ }
+ PrefixMapping prefixMap = query.getPrefixMapping();
+
+ try {
+ ResultSet results = qexec.execSelect();
+ table = convertIntoTable(prefixMap, results);
+ } finally {
+ qexec.close();
+ }
+ return table;
+ }
+
public static Model construct(Model model, String queryString) throws Exception {
Model result= null;
Query query= QueryFactory.create(queryString);
View
@@ -97,11 +97,19 @@ sparql.rdf <- function(model, sparql, rowvarname=NULL) {
return(.stringMatrix.to.matrix(stringMat, rowvarname))
}
-sparql.remote <- function(endpoint, sparql, rowvarname=NULL) {
- stringMat <- .jcall(
+sparql.remote <- function(endpoint, sparql, rowvarname=NULL, user=NA, password=NA) {
+ if (is.na(user)) {
+ stringMat <- .jcall(
"com/github/egonw/rrdf/RJenaHelper",
"Lcom/github/egonw/rrdf/StringMatrix;", "sparqlRemote", endpoint, sparql
- )
+ )
+ } else {
+ stringMat <- .jcall(
+ "com/github/egonw/rrdf/RJenaHelper",
+ "Lcom/github/egonw/rrdf/StringMatrix;", "sparqlRemote", endpoint, sparql,
+ user, password
+ )
+ }
exception <- .jgetEx(clear = TRUE)
if (!is.null(exception)) {
stop(exception)
View
Binary file not shown.
@@ -7,7 +7,7 @@ Run a SPARQL query on a remote SPARQL end point.
Runs a query against a SPARQL end point.
}
\usage{
-sparql.remote(endpoint, sparql, rowvarname)
+sparql.remote(endpoint, sparql, rowvarname, user, password)
}
\arguments{
\item{endpoint}{
@@ -19,6 +19,12 @@ The SPARQL query.
\item{rowvarname}{
Optional SPARQL variable name (without the ?) for which the values
will be used as row names of the result matrix.
+}
+ \item{user}{
+Optional user name for HTTP authentication.
+}
+ \item{password}{
+Optional password for HTTP authentication.
}
}
\value{

0 comments on commit c5bc001

Please sign in to comment.