Poolparty SPARQL使用端点的Java /球衣
问题描述:
我有,我用它来查询SPARQL端点PoolParty这curl命令:Poolparty SPARQL使用端点的Java /球衣
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: text/html" -d 'format=application/json&query=PREFIX skos:<http://www.w3.org/2004/02/skos/core#> select ?label { <http://thesaurus.iadb.org/publicthesauri/110246602490720414534842> skos:prefLabel ?label .}' http://localhost:8086/PoolParty/sparql/publicthesauri
现在我想做的使用的Java/Jersey客户端相同的查询。我的Maven的依赖关系是:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.23.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.connectors</groupId>
<artifactId>jersey-jetty-connector</artifactId>
<version>2.23.1</version>
</dependency>
,我试过的代码是:
公共字符串getLabels(查询字符串){
Client client = ClientBuilder.newClient();
WebTarget webTarget = client.target("http://localhost:8086");
webTarget.path("/PoolParty/sparql/publicthesauri");
Form form = new Form().param("format", "application/json")
.param("query", query);
Invocation.Builder invocationBuilder = webTarget.request(MediaType.TEXT_HTML);
invocationBuilder.header("Content-Type", "application/x-www-form-urlencoded");
Response response = invocationBuilder.post(Entity.form(form));
return response.readEntity(String.class));
}
此代码假设做同样的呼吁,我的curl命令但是,我能够查询Poolparty SPARQL端点如果查询,但我不能用该方法做到这一点,关于我在做什么错误的方法的任何想法?
感谢 路易斯
答
WebTarget#path
回报新WebTarget
实例。
WebTarget webTarget = client.target("http://localhost:8086");
webTarget.path("/PoolParty/sparql/publicthesauri");
所以,你到这里path
电话,不设置上webTarget
的路径。它返回一个新的。你需要链接电话。
WebTarget webTarget = client.target("http://localhost:8086")
.path("/PoolParty/sparql/publicthesauri");