Frage

My situation is simple: I have an RDF (N3) file that I want to upload into sparql-auth-endpoint. I use Jena ARQ, but unfortunately it doesn't work; I get no errors, but the graph doesn't change. Where could be the problem? My code:

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();

How can I modify the code to upload that data to the sparql-endpoint?

Edit 1

Here is a smaller example, also not working. I can create a new graph via sparql-endpoint in a browser, but in Jena I can't; no errors, no new graph.

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();

Edit 2

Using a Virtuoso server with sparql-auth-endpoint, I've changed these lines and it works much better.

UpdateProcessor processor = UpdateExecutionFactory
    .createRemoteForm(request, "http://sparql-endpoint/sparql-auth");
((UpdateProcessRemoteForm)processor).setHttpContext(httpContext);
processor.execute();

Well, it works on localhost:8890, but doesn't work in another virtuoso server

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()
War es hilfreich?

Lösung

What is the actual SPARQL Update you are reading in with this line:

UpdateRequest request = UpdateFactory.read("turtle.ttl");

Without knowing what the actual SPARQL Update is it is hard to say what is going wrong.

Guesswork...

Based on your commented out example are you trying to do something like the following:

LOAD <file:local.ttl> INTO GRAPH <http://graph>

If this is the case then this will not work, the remote server does not have access to your local file system so this command is not going to work.

Also file:local.ttl is actually an invalid URI anyway, a file URI should look like file:///local.ttl.

Edit

Per the comment I think your problem may be down to the Graph URIs being used, in all your examples you are using relative URIs so your data may not be going in the graph you expect. It's likely your data is being inserted but not into the graph you expect, if you don't have too much data you could try the following query to dump all data in named graphs to see if the data has gone somewhere:

SELECT * WHERE { GRAPH ?g { ?s ?p ?o } }

Or if you are expecting to have a small number of named graphs in the store the following will list out named graphs so you can see if you have any unexpected graphs:

SELECT DISTINCT ?g WHERE { GRAPH ?g { } }

Generally speaking it is always a good idea to use absolute URIs to ensure you are creating the data you expect in the graph you expect, relative URIs are error prone because they can resolve to different absolute URIs depending on the context in which they are resolved.

Andere Tipps

Virtuoso does not support INSERT DATA {graph <graph> {}} going by the online documentation.

400 Bad Request means syntax error from the server.

You'll need to send the request string straight to the server - because it's not SPARQL 1.1 synatx, Jena wil not parse it.

If it works in Virtuoso conductor interface (http://localhost:8890), so you could use Virtuoso Jena provider and the next code:

  String queryString = "INSERT DATA {graph <graph> ...."; // your query
  Model m = VirtModel.openDatabaseModel(file, connectionURL, username, password); 
  VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(queryString, m);
  vur.exec();  

It will sent query directly to Virtuoso server.

I had the same problem and it started to work when I added "/update" in the end of the endpoint uri.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top