1

I am using fuseki embeded from a Java application :

Dataset ds = DatasetFactory.createTxnMem() ;

FusekiEmbeddedServer server = FusekiEmbeddedServer.create()
        .setPort(3333)
        .add("/ds", ds, true)
        .build() ;
server.start() ;

The query endpoint is working fine and I can execute SELECT requests. However, when I want to insert values it does return a 204 HTTP code but no data is added to the graph. Here is what I did :

PREFIX dc: <http://purl.org/dc/elements/1.1/>INSERT DATA{ <http://example/book3> dc:title "A new book"}

<Response [204]>

then I select everything to see if it worked :

SELECT DISTINCT * WHERE {?s ?q ?o}

and I get

<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
  <head>
    <variable name="s"/>
    <variable name="q"/>
    <variable name="o"/>
  </head>
  <results>
  </results>
</sparql>

On the client side I have a basic python script :

port = 3333
test_add = 'PREFIX dc: <http://purl.org/dc/elements/1.1/>INSERT DATA{ <http://example/book3> dc:title "A new book"}'
try :
    print requests.post("http://localhost:"+str(port)+"/ds", data={'update': test_add})
    print urllib2.urlopen("http://localhost:"+str(port)+"/ds?query=SELECT%20DISTINCT%20*%20WHERE%20{?s%20?q%20?o}").read()

except Exception as e :
    print e

This python script works now, it has been adapted from the answer below.

Yotm
  • 45
  • 4
  • Could you please show the client-side code making the operations? – AndyS Jul 20 '17 at 17:00
  • It is just a very basic python script (i added it to the question). I tested several things in the test_add variable – Yotm Jul 20 '17 at 17:28
  • Can you try to create the server without the boolean argument? Maybe it's read-only via HTTP. – UninformedUser Jul 20 '17 at 18:25
  • It still doesn't work without the boolean. This boolean is correspond to the allowUpdate parameter, I guess it should be true if we want to allow modifications – Yotm Jul 20 '17 at 19:43

1 Answers1

0

This is maybe not a good answer but just to show you that it works for me.

Jena Fuseki 2.6.0

Start embedded server

public class FusekiTestServer {
    public static void main(String[] args) {
        Dataset ds = DatasetFactory.createTxnMem() ;

        FusekiEmbeddedServer server = FusekiEmbeddedServer.create()
                .setPort(3333)
                .add("/ds", ds, true)
                .build() ;
        server.start() ;
    }
}

Insert data

Request

curl --request POST http://localhost:3333/ds --data-urlencode 'update=PREFIX dc: <http://purl.org/dc/elements/1.1/>INSERT DATA{ <http://example/book3> dc:title "A new book"}'

Output

<html>
<head>
</head>
<body>
<h1>Success</h1>
<p>
Update succeeded
</p>
</body>
</html>

Query data

Request

curl --request GET http://localhost:3333/ds --data-urlencode 'query=SELECT DISTINCT * WHERE {?s ?q ?o}'

Output

<http://example/book3>
        <http://purl.org/dc/elements/1.1/title>
                "A new book" .

Diagnosis

I'm not a Python expert, but shouldn't the query string be put into the data array as it's a POST request? Something like

requests.post("http://localhost:"+str(port)+"/ds, data={'update': 'PREFIX dc: <http://purl.org/dc/elements/1.1/>INSERT DATA{ <http://example/book3> dc:title "A new book"}'})
UninformedUser
  • 8,397
  • 1
  • 14
  • 23
  • You're completely right, it makes no sense to use a POST like a GET. I don't know why I did that. I tried to put the querry in the data before and it wasn't working. I must have forgot something at the time. When I tried it this morning it was working ! Thanks a lot, I'll update my code – Yotm Jul 21 '17 at 14:14