我的情况很简单:我有一个要上传到 sparql-auth-endpoint 的 RDF (N3) 文件。我使用 Jena ARQ,但不幸的是它不起作用;我没有收到任何错误,但图表没有改变。问题可能出在哪里?我的代码:
HttpContext httpContext = new BasicHttpContext();
CredentialsProvider provider = new BasicCredentialsProvider();
provider.setCredentials(new AuthScope(AuthScope.ANY_HOST,
AuthScope.ANY_PORT), new UsernamePasswordCredentials("user", "pass"));
httpContext.setAttribute(ClientContext.CREDS_PROVIDER, provider);
GraphStore graphStore = GraphStoreFactory.create() ;
UpdateRequest request = UpdateFactory.read("turtle.ttl");
/*another possible query, same result - no errors but the graph doesn't change
request.add(new UpdateCreate("graph")) ;
request.add(new UpdateLoad("file:turtle_2.ttl", "graph")) ;
request.add("prefix dcterms: <http://purl.org/dc/terms/>"
+ "INSERT DATA { GRAPH <graph> {<http://example/book3> dcterms:title \"A new book\" }}");
UpdateAction.execute(request, graphStore) ;
*/
UpdateProcessor processor = UpdateExecutionFactory
.createRemote(request, "http://sparql-endpoint/sparql-auth");
((UpdateProcessRemote)processor).setHttpContext(httpContext);
processor.execute();
如何修改代码以将该数据上传到 sparql-endpoint?
编辑 1
这是一个较小的示例,也不起作用。我可以在浏览器中通过 sparql-endpoint 创建一个新图形,但在 Jena 我不能;没有错误,没有新图表。
UpdateRequest request = UpdateFactory.create();
request.add(new UpdateCreate("http://linkeddata.com/graph"));
UpdateProcessor processor = UpdateExecutionFactory
.createRemote(request, "http://sparql-endpoint/sparql-auth");
((UpdateProcessRemote)processor).setHttpContext(httpContext);
processor.execute();
编辑 2
使用带有 sparql-auth-endpoint 的 Virtuoso 服务器,我更改了这些行并且效果更好。
UpdateProcessor processor = UpdateExecutionFactory
.createRemoteForm(request, "http://sparql-endpoint/sparql-auth");
((UpdateProcessRemoteForm)processor).setHttpContext(httpContext);
processor.execute();
好吧,它可以在 localhost:8890 上运行,但不能在另一个 virtuoso 服务器上运行
Exception in thread "main" org.apache.jena.atlas.web.HttpException: 400 Bad Request
at org.apache.jena.riot.web.HttpOp.httpResponse(HttpOp.java:425)
at org.apache.jena.riot.web.HttpOp.execHttpPostForm(HttpOp.java:316)
at com.hp.hpl.jena.sparql.modify.UpdateProcessRemoteForm.execute(UpdateProcessRemoteForm.java:75)
at bakalarska_prace.UpVirtuoso.main(UpVirtuoso.java:108) -> processor.execute()