From 5c42c1f315956e1ab13204fddcaa45afe78dba3c Mon Sep 17 00:00:00 2001 From: Luigi Asprino Date: Wed, 20 Nov 2024 14:15:03 +0100 Subject: [PATCH] #515 --- .../io/github/sparqlanything/it/IssuesTest.java | 8 ++++++++ .../src/test/resources/issues/issue515.something | 1 + .../src/test/resources/issues/issue515.sparql | 15 +++++++++++++++ .../github/sparqlanything/rdf/RDFTriplifier.java | 12 ++++++------ 4 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 sparql-anything-it/src/test/resources/issues/issue515.something create mode 100644 sparql-anything-it/src/test/resources/issues/issue515.sparql diff --git a/sparql-anything-it/src/test/java/io/github/sparqlanything/it/IssuesTest.java b/sparql-anything-it/src/test/java/io/github/sparqlanything/it/IssuesTest.java index b9037319..1a795348 100644 --- a/sparql-anything-it/src/test/java/io/github/sparqlanything/it/IssuesTest.java +++ b/sparql-anything-it/src/test/java/io/github/sparqlanything/it/IssuesTest.java @@ -968,6 +968,14 @@ public void testIssue429() throws URISyntaxException, IOException { // assertFalse(rs.hasNext()); } + @Test + public void testIssue515() throws URISyntaxException, IOException { + QueryExecution qExec = executeTest("issues/issue515.sparql", "issues/issue515.something", false, false, false, false); + ResultSet rs = qExec.execSelect(); + assertTrue(rs.hasNext()); + } + + private QueryExecution executeTest(String queryPath, String resourcePath, boolean printQueryString, boolean printFormattedQuery, boolean printResults, boolean constructResource) throws IOException, URISyntaxException { Dataset ds = DatasetFactory.createGeneral(); QC.setFactory(ARQ.getContext(), FacadeX.ExecutorFactory); diff --git a/sparql-anything-it/src/test/resources/issues/issue515.something b/sparql-anything-it/src/test/resources/issues/issue515.something new file mode 100644 index 00000000..ce002f06 --- /dev/null +++ b/sparql-anything-it/src/test/resources/issues/issue515.something @@ -0,0 +1 @@ + . \ No newline at end of file diff --git a/sparql-anything-it/src/test/resources/issues/issue515.sparql b/sparql-anything-it/src/test/resources/issues/issue515.sparql new file mode 100644 index 00000000..4b3bd4e9 --- /dev/null +++ b/sparql-anything-it/src/test/resources/issues/issue515.sparql @@ -0,0 +1,15 @@ +PREFIX fx: +PREFIX xyz: +PREFIX owl: +PREFIX rdfs: + +SELECT * +WHERE { + { + SERVICE { + fx:properties fx:media-type "text/turtle" ; + fx:location "%%%LOCATION%%%" . + ?s ?p ?o . + } + } +} \ No newline at end of file diff --git a/sparql-anything-rdf/src/main/java/io/github/sparqlanything/rdf/RDFTriplifier.java b/sparql-anything-rdf/src/main/java/io/github/sparqlanything/rdf/RDFTriplifier.java index ec94c236..62e38d75 100644 --- a/sparql-anything-rdf/src/main/java/io/github/sparqlanything/rdf/RDFTriplifier.java +++ b/sparql-anything-rdf/src/main/java/io/github/sparqlanything/rdf/RDFTriplifier.java @@ -16,10 +16,7 @@ package io.github.sparqlanything.rdf; -import io.github.sparqlanything.model.FacadeXGraphBuilder; -import io.github.sparqlanything.model.HTTPHelper; -import io.github.sparqlanything.model.Triplifier; -import io.github.sparqlanything.model.TriplifierHTTPException; +import io.github.sparqlanything.model.*; import org.apache.commons.io.IOUtils; import org.apache.http.Header; import org.apache.http.client.methods.CloseableHttpResponse; @@ -44,7 +41,7 @@ public class RDFTriplifier implements Triplifier { // private static Logger logger = LoggerFactory.getLogger(RDFTriplifier.class); - public static Lang getRDFLang(Properties properties, String url, Header contentType) { + private static Lang getRDFLang(Properties properties, String url, Header contentType) { Lang lang = null; // Version from HTTP content type response @@ -60,6 +57,9 @@ public static Lang getRDFLang(Properties properties, String url, Header contentT if (lang == null && properties.containsKey(HTTPHelper.HTTPHEADER_PREFIX + "accept")) { lang = RDFLanguages.contentTypeToLang(properties.getProperty(HTTPHelper.HTTPHEADER_PREFIX + "accept")); } + if (lang == null && properties.containsKey(IRIArgument.MEDIA_TYPE.toString())) { + lang = RDFLanguages.contentTypeToLang(PropertyUtils.getStringProperty(properties, IRIArgument.MEDIA_TYPE)); + } if (lang == null) { // Version from location file extension lang = RDFLanguages.filenameToLang(url); @@ -72,7 +72,7 @@ public static Lang getRDFLang(Properties properties, String url, Header contentT // However, the JSON is not a proper LANG, therefore, we rewrite it here // See #356 // See io.github.sparqlanything.cli.SPARQLAnything.initSPARQLAnythingEngine() - if(lang.getLabel().equals("JSON")){ + if(lang!=null && lang.getLabel().equals("JSON")){ lang = Lang.JSONLD; } log.trace("Lang {}", lang);