ParameterList aParams = new ParameterList()
.add(PARAM_QUERY, theQuery);
Request aQueryRequest;
Response aResponse = null;
try {
if (mUseGetForQueries) {
aQueryRequest = aRes.initGet()
.addHeader(HttpHeaders.Accept.getName(), RDFFormat.TURTLE.getDefaultMIMEType())
.setParameters(aParams);
}
else {
aQueryRequest = aRes.initPost()
.addHeader(HttpHeaders.ContentType.getName(), MimeTypes.FormUrlEncoded.getMimeType())
.addHeader(HttpHeaders.Accept.getName(), RDFFormat.TURTLE.getDefaultMIMEType())
.setBody(aParams.getURLEncoded());
}
aResponse = aQueryRequest.execute();
if (aResponse.hasErrorCode()) {
throw responseToException(theQuery, aResponse);
}
else {
try {
return GraphIO.readGraph(aResponse.getContent(), RDFFormat.TURTLE);
}
catch (RDFParseException e) {
throw new QueryException("Error while parsing rdf/xml-formatted query results", e);
}
}
}
catch (IOException e) {
throw new QueryException(e);
}
finally {
if (aResponse != null) {
try {
aResponse.close();
}
catch (IOException e) {
System.err.println("There was an error while closing the http connection: " + e.getMessage());
}
}