如何将http标头添加到Apache Jena QueryEngineHTTP查询?

时间:2017-02-09 10:36:27

标签: rest http-headers jena

我尝试使用HTTP标头,以便我可以对我的应用进行身份验证,以查询ORCID(http://orcid.org)公共API。我创建了这样的标题:

HttpOptions httpOptions = new HttpOptions();
Header contentTypeHeader = new BasicHeader("Content-Type", "application/orcid+json");
Header authorizationHeader = new BasicHeader("Authorization", "Bearer 5266384f-0567-43f0-9cd4-bc6f6a5dc3ea");
Header[] headers = new Header[2];
headers[1] = contentTypeHeader;
headers[2] = authorizationHeader;
httpOptions.setHeaders(headers);

但我不知道如何将这些标题放入我的查询中。我这样写我的查询:

QueryExecution execution = new QueryEngineHTTP(endpoint, query);

使用org.apache.jena.sparql.engine.http.QueryEngineHTTP

1 个答案:

答案 0 :(得分:0)

Apache Jena现在(v3.1.1及更高版本)提供了通过必要的安全设置传递HttpClient的方法。

Docmentation

... set up an appropriate HttpClient for authentication ....

QueryExecution execution = QueryExecutionFactory.sparqlService( ... , httpClient)