Blazegraph REST POST请求在转换为Java时无法正常工作

时间:2016-12-14 10:57:04

标签: java xml graph sparql blazegraph

我正在使用基础方法将RDF数据发布到Bazegraph中,但遗憾的是,当我在Blazegraph UI的查询中select * {?s ?p ?o}时,我无法找到任何数据。

发布请求的Curl命令:

curl -X POST -H 'Content-Type:text/x-nquads' --data-binary '@data-1.nq' 
http://localhost:8080/bigdata/sparql

我在Java中发布的代码:

String url = "http://localhost:9999/bigdata/sparql";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();

//add reuqest header
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", USER_AGENT);

con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
con.setRequestProperty("Content-Type","text/x-nquads");

byte[] array = Files.readAllBytes(new File("my.nq").toPath());
System.out.println(array);
con.setRequestProperty("Content-Length", String.valueOf(array.length));

// Send post request
con.setDoOutput(true);

DataOutputStream wr = new DataOutputStream( con.getOutputStream()) ;
    wr.write( array );
    wr.flush();
    wr.close();

int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Response Code : " + responseCode);

BufferedReader in = new BufferedReader(
        new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();

//print result
System.out.println(response.toString());

my.nq 文件包含:

@prefix f:    <http://example.org#> .
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
f:john a foaf:Person .
f:bill a foaf:Person .
f:mary a foaf:Person .
f:jane a foaf:Person .
f:john f:age "25"^^xsd:int .
f:bill f:age "30"^^xsd:int .
f:mary f:age "24"^^xsd:int .
f:jane f:age "26"^^xsd:int .
f:john f:loves f:mary .
f:bill f:loves f:jane .
f:john f:hasFriend f:bill.
f:john f:name "John Roy" .
f:bill f:name "Bill Jou" .
f:mary f:name "Mary Lestern" .
f:jane f:name "Jane Caiton" .
f:bill foaf:name "Bill" .
f:john foaf:name "John" .
f:mary foaf:name "Mary" .
f:jane foaf:name "Jane" .

0 个答案:

没有答案