Skip to content

SPARQL HTTP client: Header config is ignored for non-parsed queries #3448

@Aklakan

Description

@Aklakan

Version

5.6.0-SNAPSHOT

What happened?

When sending queries without parsing parseCheck(false) to a remote endpoint, then the configured headers are not considered. Instead, default headers are used instead.
The reason is QueryExecHTTPBuilder chooses one header based on the parsed query type and passes it as an override to QueryExecHTTP. Because for non-parsed queries the override cannot be determined, a fallback to */* is made.

As a proposed solution, QueryExecHTTP should choose the header based on the API usage - calling select() should use the header configured for select - for parsed queries, a consistency check between the API call and query type is already made anyway.

The following example should fail with 406 Not Acceptable but unexpectedly works:

	public static void main(String[] args) {
		// Note that the query string uses the prefix 'rdfs:' without declaring it.
		// The DBpedia server can parse such a query against its configured prefixes.
		String queryString = "SELECT * { <http://dbpedia.org/resource/Apache_Jena> rdfs:label ?l } ORDER BY ?l LIMIT 1";

		try (RDFConnection conn = RDFConnectionRemote.service("http://dbpedia.org/sparql")
                // This header is not supported by DBpedia:
				.acceptHeaderSelectQuery(WebContent.contentTypeResultsThrift)
				.parseCheckSPARQL(false).build()) {
			try (QueryExecution qe = conn.query(queryString)) {
				ResultSet rs = qe.execSelect();
				ResultSetFormatter.output(System.out, rs, ResultsFormat.FMT_TEXT);
			}
		}
	}

Relevant output and stacktrace

Are you interested in making a pull request?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions