首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Jena ARQ以基本auth - preemptive方式访问远程存储库

使用Jena ARQ以基本auth - preemptive方式访问远程存储库
EN

Stack Overflow用户
提问于 2014-01-15 20:06:52
回答 1查看 554关注 0票数 1

我正在尝试使用带有PreemptiveBasicAuthenticator的Jena ARQ,但是没有成功,有谁可以帮助我吗?

我总是得到一个401,尽管同样的请求通过rest客户端,或使用openrdf工作。这会不会与apache http客户端和必须设置AuthScope有关?

代码语言:javascript
复制
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();
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21137012

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档