我正在开发一个使用DBpedia数据集的项目,我想通过它们提供的sparql端点远程连接它们。现在我必须在大学代理服务器后面工作,我不能让我的代码连接到DBpedia sparql端点。到目前为止,我试图通过System.getProperties()设置代理设置,但它仍然无法正常工作并抛出一个未知的主机异常。我在下面附加了我的代码段以及抛出的异常。任何建议都会受到欢迎。
System.getProperties().put("proxySet","true");
System.getProperties().put("http.proxyHost", "http://username:pwd@172.31.1.6");
System.getProperties().put("proxyPort",8080);
String q= "SELECT ?p ?o WHERE { <http://dbpedia.org/resource/Mendelian_inheritance> ?p ?o . }";
Query query = QueryFactory.create(q);
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
ResultSet results = qexec.execSelect();
while (results.hasNext()) {
QuerySolution result = results.nextSolution();
RDFNode s = result.get("s");
RDFNode p = result.get("p");
RDFNode o = result.get("o");
System.out.println( " { " + s + " " + p + " " + o + " . }");
}
抛出的异常如下:
Exception in thread "main" HttpException: java.net.UnknownHostException: dbpedia.org: java.net.UnknownHostException: dbpedia.org
at com.hp.hpl.jena.sparql.engine.http.HttpQuery.execGet(HttpQuery.java:203)
at com.hp.hpl.jena.sparql.engine.http.HttpQuery.exec(HttpQuery.java:144)
at com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execSelect(QueryEngineHTTP.java:141)
at project6.Main.main(Main.java:53)
Caused by: java.net.UnknownHostException: dbpedia.org
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
....
就像一个页脚我尝试将sparql网址设置为http://dbpedia.org/snorql
答案 0 :(得分:1)
也许您应该使用“http.proxyPort”而不是“proxyPort”。 :-) 并且,System有一个可以使用的setProperty(String key,String value)方法。