Search code examples
sparqlrdfamazon-neptunerdf-xml

IRI included an unencoded space Error when posted to SparQL Client on Neptune Server


I am getting this following error when making a POST request to my SPARQL Client endpoint:

Malformed query: org.openrdf.rio.RDFParseException: IRI included an unencoded space: '32' [line 1]

I am using Postman to make the request and have set a single header which is Content-Type and has the value sparql-update.

The data that I am passing in the body is like this:

insert data { <rdf:RDF xmlns:html="http://www.w3.org/1999/xhtml"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:country="http://example.xyz.ds/country/"
         xmlns:currency="http://example.xyz.ds/currency/"
         xmlns:area="http://example.xyz.ds/area/"
         xmlns:city="http://example.xyz.ds/city/"
         xmlns:root="http://example.xyz.ds/terms#"
         xmlns:specialIdenifier="http://example.xyz.ds/specialIdenifier/"
         xmlns:product="http://example.xyz.ds/product/"
         xmlns:company="http://example.xyz.ds/company/"
         xmlns:office="http://example.xyz.ds/office/"
         xmlns:schema="http://schema.org/"
         xmlns:uuid="java:java.util.UUID"
         xmlns:acmUtil="http://example.xyz.ds/util-functions">
    <rdf:Description rdf:about="http://example.xyz.ds/company/123456789>
        <rdf:type rdf:resource="http://example.xyz.ds/terms#company"/>
        <rdfs:label/>
        <root:fid xmlns:urn="urn:"
                  xmlns:func="http://example.xyz.ds/func"
                  rdf:datatype="http://www.w3.org/2001/XMLSchema#string">4049</root:fid>
        <root:deleted xmlns:urn="urn:"
                      xmlns:func="http://example.xyz.ds/func"
                      rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">false</root:deleted>
    </rdf:Description>
</rdf:RDF> }

I am hoping that I can just POST this entire RDF XML document in the body and the SPARQL client/Neptune database will just understand the triples within it.

I have seen a lot online about this error but can't find a solution related to POSTing the data directly. Any idea how to solve this problem?


Solution

  • As discussed in the comments, your SPARQL command is not syntactically valid: you can't just paste an RDF/XML document inside a SPARQL INSERT DATA command (see the SPARQL Update specification for details on correct syntax).

    I am hoping that I can just POST this entire RDF XML document in the body and the SPARQL client/Neptune database will just understand the triples within it.

    Unfortunately, Neptune has no option for that (at least, not as far as I can see from the Neptune docs).

    You can upload an RDF/XML document to Neptune by using the UPDATE LOAD command, as shown in the Neptune documentation. If that is not an option for you, you will need to convert the data in the document to correct SPARQL syntax somehow.

    There are several ways to to this, but if you're working in Java, one possible option is to use the rdf4j Repository API. You can connect to your Neptune instance's SPARQL endpoint using the SPARQLRepository class, as follows:

    Repository rep = new SPARQLRepository("https://your-neptune-endpoint:port/sparql");
    rep.init();
    

    and then you can just open a connection and load your file that way:

    try(RepositoryConnection conn = rep.getConnection()) {
          File file = new File("/my/local/rdf-xml-file.rdf");
          conn.add(file, "", RDFFormat.RDFXML);
    }
    

    Rdf4j will take care of converting your command into a SPARQL update request that the Neptune server can understand (slight caveat: I haven't tested this myself with Neptune, but if it is compliant with the SPARQL W3C Recommendations this should work).