gpt4 book ai didi

java - 使用 Jena ARQ 通过基本身份验证访问远程存储库 - 抢占式

转载 作者:太空宇宙 更新时间:2023-11-04 15:12:58 26 4
gpt4 key购买 nike

我正在尝试将 Jena ARQ 与 PreemptiveBasicAuthenticator 一起使用,但没有成功,有人可以帮忙吗?

我总是收到 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();
}
}
}

最佳答案

关于java - 使用 Jena ARQ 通过基本身份验证访问远程存储库 - 抢占式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21137012/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com