Strange behavior of content negotiation concerning SPARQL CONSTRUCT query

我的梦境 提交于 2021-01-29 08:28:40

问题


When issuing a SPARQL CONSTRUCT query to a specific endpoint, Apache Jena library 3.14.0 issues an error message as follows.

Endpoint returned Content Type: application/sparql-results+xml which is not a valid RDF syntax

The code I wrote is as follows.

QueryEngineHTTP qeh = new QueryEngineHTTP(endpointUrl, rq);
qeh.setAcceptHeader("application/rdf+xml");
Model m = qeh.execConstruct();

The endpoint is https://id.nlm.nih.gov/mesh/sparql . The query is as follows.

CONSTRUCT {?s <http://id.nlm.nih.gov/mesh/vocab#altLabel> ?o}
FROM <http://id.nlm.nih.gov/mesh/2020>
WHERE {
  ?s <http://id.nlm.nih.gov/mesh/vocab#altLabel> ?o ;
    a <http://id.nlm.nih.gov/mesh/vocab#Term> .
  FILTER(isLiteral(?o))
} LIMIT 3

When issuing this query by the curl tool, I got a fine result.

% curl -LH 'Accept: application/rdf+xml' --data-urlencode query@test.rq https://id.nlm.nih.gov/mesh/sparql
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:j.0="http://id.nlm.nih.gov/mesh/vocab#">
  <rdf:Description rdf:about="http://id.nlm.nih.gov/mesh/2020/T000963157">
    <j.0:altLabel xml:lang="en">Topics, Exhibitions as</j.0:altLabel>
  </rdf:Description>
  <rdf:Description rdf:about="http://id.nlm.nih.gov/mesh/2020/T000950545">
    <j.0:altLabel xml:lang="en">Psychiatric Fetishism</j.0:altLabel>
  </rdf:Description>
  <rdf:Description rdf:about="http://id.nlm.nih.gov/mesh/2020/T000950541">
    <j.0:altLabel xml:lang="en">Psychological Extraversion</j.0:altLabel>
  </rdf:Description>
</rdf:RDF>

来源:https://stackoverflow.com/questions/64887803/strange-behavior-of-content-negotiation-concerning-sparql-construct-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!