Aklakan opened a new issue, #2233:
URL: https://github.com/apache/jena/issues/2233
### Version
5.0.0-SNAPSHOT
### What happened?
Setting headers explicitly using e.g.
`.acceptHeaderSelectQuery(WebContent.contentTypeResultsXML)` does not work
consistently across the APIs.
Only `RDFConnection.query(queryObject)` works as expected.
* For query *strings*, internally the query type is always considered
QueryType.UNKNOWN and the custom header is ignored - even if query parsing is
enabled (it is by default):
https://github.com/apache/jena/blob/0fd96b64e1f404477eb8f95cefa49c776d907c27/jena-rdfconnection/src/main/java/org/apache/jena/rdflink/RDFLinkHTTP.java#L256
* For query *objects*, using `RDFConnection.newQuery()` does not forward the
header:
See
https://github.com/apache/jena/blob/0fd96b64e1f404477eb8f95cefa49c776d907c27/jena-rdfconnection/src/main/java/org/apache/jena/rdflink/RDFLinkHTTP.java#L268
```java
class Test {
public static void main(String[] args) {
JenaSystem.init();
try (RDFConnection conn = RDFConnectionRemote.newBuilder()
.queryEndpoint("https://dbpedia.org/sparql")
.acceptHeaderSelectQuery(WebContent.contentTypeResultsXML)
.build()) {
String queryStr = "SELECT * { ?s <urn:bar> <urn:baz> }";
System.out.println("String - Direct");
// DEBUG org.apache.jena.http.HTTP: > GET
https://dbpedia.org/sparql?query=SELECT%20%2A%20%7B%20?s%20%3Curn:bar%3E%20%3Curn:baz%3E%20%7D
// DEBUG org.apache.jena.http.HTTP: Accept
application/sparql-results+json, application/sparql-results+xml;q=0.9,
text/tab-separated-values;q=0.7,
text/csv;q=0.5,application/json;q=0.2,application/xml;q=0.2,*/*;q=0.1
try (QueryExecution qe = conn.query(queryStr)) {
ResultSet rs = qe.execSelect().materialise();
System.out.println(ResultSetFormatter.asText(rs));
}
System.out.println("String - Builder");
// DEBUG org.apache.jena.http.HTTP: > GET
https://dbpedia.org/sparql?query=SELECT%20%2A%20%7B%20?s%20%3Curn:bar%3E%20%3Curn:baz%3E%20%7D
// DEBUG org.apache.jena.http.HTTP: Accept
application/sparql-results+json, application/sparql-results+xml;q=0.9,
text/tab-separated-values;q=0.7,
text/csv;q=0.5,application/json;q=0.2,application/xml;q=0.2,*/*;q=0.1
try (QueryExecution qe = conn.newQuery().query(queryStr).build()) {
ResultSet rs = qe.execSelect().materialise();
System.out.println(ResultSetFormatter.asText(rs));
}
Query query = QueryFactory.create(queryStr);
System.out.println("Query - Direct");
// DEBUG org.apache.jena.http.HTTP: > GET
https://dbpedia.org/sparql?query=SELECT%20%20%2A%0AWHERE%0A%20%20%7B%20?s%20%20%3Curn:bar%3E%20%20%3Curn:baz%3E%20%7D%0A
// DEBUG org.apache.jena.http.HTTP: Accept
application/sparql-results+xml
try (QueryExecution qe = conn.query(query)) {
ResultSet rs = qe.execSelect().materialise();
System.out.println(ResultSetFormatter.asText(rs));
}
System.out.println("Query - Builder");
// DEBUG org.apache.jena.http.HTTP: > GET
https://dbpedia.org/sparql?query=SELECT%20%20%2A%0AWHERE%0A%20%20%7B%20?s%20%20%3Curn:bar%3E%20%20%3Curn:baz%3E%20%7D%0A
// DEBUG org.apache.jena.http.HTTP: Accept
application/sparql-results+json, application/sparql-results+xml;q=0.9,
text/tab-separated-values;q=0.7,
text/csv;q=0.5,application/json;q=0.2,application/xml;q=0.2,*/*;q=0.1
try (QueryExecution qe = conn.newQuery().query(query).build()) {
ResultSet rs = qe.execSelect().materialise();
System.out.println(ResultSetFormatter.asText(rs));
}
}
}
}
```
### Relevant output and stacktrace
_No response_
### Are you interested in making a pull request?
Maybe
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]