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