我正在尝试使用带有PreemptiveBasicAuthenticator的Jena ARQ,但是没有成功,有谁可以帮助我吗?
我总是得到一个401,尽管同样的请求通过rest客户端,或使用openrdf工作。这会不会与apache http客户端和必须设置AuthScope有关?
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSet;
import org.apache.jena.atlas.web.auth.HttpAuthenticator;
import org.apache.jena.atlas.web.auth.PreemptiveBasicAuthenticator;
import org.apache.jena.atlas.web.auth.ScopedAuthenticator;
import java.net.URI;
public class JenaConnect {
private final static String SPARQLR_ENDPOINT = "https://repo-eh-01.sparqlr.com/repositories/examples-repo";
private final static String SPARQLR_USERNAME = "examples-repo";
private final static String SPARQLR_PASSWORD = "XXXX";
public static void main(String[] args) throws Exception {
String queryString = "SELECT * WHERE {?s ?p ?o}";
Query query = QueryFactory.create(queryString);
HttpAuthenticator authenticator = new PreemptiveBasicAuthenticator(
new ScopedAuthenticator(new URI(SPARQLR_ENDPOINT), SPARQLR_USERNAME, SPARQLR_PASSWORD.toCharArray())
);
QueryExecution queryExecution = QueryExecutionFactory.sparqlService(SPARQLR_ENDPOINT, query, authenticator);
try {
ResultSet results = queryExecution.execSelect();
int i = 0;
while(results.hasNext()) {
results.next();
i++;
}
System.out.println(i);
} finally {
queryExecution.close();
}
}
}发布于 2014-01-17 01:33:38
在此帖子中问答:http://mail-archives.apache.org/mod_mbox/jena-users/201401.mbox/%3CF6F103F1-7205-4E6B-94EB-FEB67129A39A%40sparqlr.com%3E
https://stackoverflow.com/questions/21137012
复制相似问题