Skip to content

Commit a304c44

Browse files
committed
Namespace endpoint handles queries with relative URIs
The relative URIs are resolved against the endpoint URL as the base URI HTTP tests included
1 parent 201665f commit a304c44

4 files changed

Lines changed: 86 additions & 1 deletion

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
initialize_dataset "$END_USER_BASE_URL" "$TMP_END_USER_DATASET" "$END_USER_ENDPOINT_URL"
5+
initialize_dataset "$ADMIN_BASE_URL" "$TMP_ADMIN_DATASET" "$ADMIN_ENDPOINT_URL"
6+
purge_cache "$END_USER_VARNISH_SERVICE"
7+
purge_cache "$ADMIN_VARNISH_SERVICE"
8+
purge_cache "$FRONTEND_VARNISH_SERVICE"
9+
10+
# create class in the namespace ontology
11+
12+
namespace_doc="${END_USER_BASE_URL}ns"
13+
namespace="${namespace_doc}#"
14+
ontology_doc="${ADMIN_BASE_URL}ontologies/namespace/"
15+
class="${namespace}NewClass"
16+
17+
add-class.sh \
18+
-f "$OWNER_CERT_FILE" \
19+
-p "$OWNER_CERT_PWD" \
20+
-b "$ADMIN_BASE_URL" \
21+
--uri "$class" \
22+
--label "New class" \
23+
"$ontology_doc"
24+
25+
# clear ontology from memory
26+
27+
clear-ontology.sh \
28+
-f "$OWNER_CERT_FILE" \
29+
-p "$OWNER_CERT_PWD" \
30+
-b "$ADMIN_BASE_URL" \
31+
--ontology "$namespace"
32+
33+
# query using relative URI - <#NewClass> should resolve to ${namespace_doc}#NewClass
34+
35+
curl -k -s -G \
36+
-E "$OWNER_CERT_FILE":"$OWNER_CERT_PWD" \
37+
-H "Accept: application/sparql-results+xml" \
38+
"${namespace_doc}" \
39+
--data-urlencode "query=SELECT * { <#NewClass> ?p ?o }" \
40+
| grep '<literal>New class</literal>' > /dev/null
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
initialize_dataset "$END_USER_BASE_URL" "$TMP_END_USER_DATASET" "$END_USER_ENDPOINT_URL"
5+
initialize_dataset "$ADMIN_BASE_URL" "$TMP_ADMIN_DATASET" "$ADMIN_ENDPOINT_URL"
6+
purge_cache "$END_USER_VARNISH_SERVICE"
7+
purge_cache "$ADMIN_VARNISH_SERVICE"
8+
purge_cache "$FRONTEND_VARNISH_SERVICE"
9+
10+
# create class in the namespace ontology
11+
12+
namespace_doc="${END_USER_BASE_URL}ns"
13+
namespace="${namespace_doc}#"
14+
ontology_doc="${ADMIN_BASE_URL}ontologies/namespace/"
15+
class="${namespace}NewClass"
16+
17+
add-class.sh \
18+
-f "$OWNER_CERT_FILE" \
19+
-p "$OWNER_CERT_PWD" \
20+
-b "$ADMIN_BASE_URL" \
21+
--uri "$class" \
22+
--label "New class" \
23+
"$ontology_doc"
24+
25+
# clear ontology from memory
26+
27+
clear-ontology.sh \
28+
-f "$OWNER_CERT_FILE" \
29+
-p "$OWNER_CERT_PWD" \
30+
-b "$ADMIN_BASE_URL" \
31+
--ontology "$namespace"
32+
33+
# query using relative URI - <#NewClass> should resolve to ${namespace_doc}#NewClass
34+
35+
curl -k -s -X POST \
36+
-E "$OWNER_CERT_FILE":"$OWNER_CERT_PWD" \
37+
-H "Accept: application/sparql-results+xml" \
38+
-H "Content-Type: application/x-www-form-urlencoded" \
39+
"${namespace_doc}" \
40+
--data-urlencode "query=SELECT * { <#NewClass> ?p ?o }" \
41+
| grep '<literal>New class</literal>' > /dev/null

src/main/java/com/atomgraph/linkeddatahub/resource/Namespace.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.apache.jena.ontology.Ontology;
5252
import org.apache.jena.query.DatasetFactory;
5353
import org.apache.jena.query.Query;
54+
import org.apache.jena.query.QueryFactory;
5455
import org.apache.jena.rdf.model.Model;
5556
import org.apache.jena.rdf.model.ModelFactory;
5657
import org.apache.jena.riot.system.Checker;
@@ -148,6 +149,8 @@ public Response get(@QueryParam(QUERY) Query query,
148149
else throw new BadRequestException("SPARQL query string not provided");
149150
}
150151

152+
// re-parse query to set explicit fallback base URI
153+
query = QueryFactory.create(query.toString(), getUriInfo().getAbsolutePath().toString());
151154
return super.get(query, defaultGraphUris, namedGraphUris);
152155
}
153156

@@ -160,6 +163,8 @@ public Response post(@FormParam(QUERY) String queryString, @FormParam(UPDATE) St
160163
{
161164
if (updateString != null) throw new WebApplicationException("SPARQL updates are not allowed on the <ns> endpoint", Status.METHOD_NOT_ALLOWED);
162165

166+
// re-parse query to set explicit fallback base URI
167+
queryString = QueryFactory.create(queryString, getUriInfo().getAbsolutePath().toString()).toString();
163168
return super.post(queryString, updateString, defaultGraphUris, namedGraphUris, usingGraphUris, usingNamedGraphUris);
164169
}
165170

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/layout.xsl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ exclude-result-prefixes="#all">
100100

101101
<xsl:output method="xhtml" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" media-type="application/xhtml+xml"/>
102102

103-
<!-- <xsl:param name="ldh:base" as="xs:anyURI" static="yes"/>-->
104103
<xsl:param name="lapp:origin" as="xs:anyURI"/>
105104
<xsl:param name="ldh:requestUri" as="xs:anyURI"/>
106105
<xsl:param name="ac:endpoint" select="resolve-uri('sparql', $ldt:base)" as="xs:anyURI"/>

0 commit comments

Comments
 (0)