if (u.length() > QUERY_LIMIT) {
// POST connection
try {
req = new HttpPost(url.toURI());
} catch (URISyntaxException e) {
throw new SparqlException("Endpoint <" + url + "> not in an acceptable format", e);
}
((HttpPost) req).setEntity((HttpEntity) new StringEntity(params));
} else {
// GET connection
req = new HttpGet(u);
}
if (command.getTimeout() != Command.NO_TIMEOUT) {
HttpParams reqParams = new BasicHttpParams();
HttpConnectionParams.setSoTimeout(reqParams, (int) (command.getTimeout() * 1000));
req.setParams(reqParams);
}
// Add Accept and Content-Type (for POST'ed queries) headers to the request.
addHeaders(req, mimeType);
// There's a small chance the request could be aborted before it's even executed, we'll have to live with that.
command.setRequest(req);
//dump(client, req);
HttpResponse response = client.execute(req);
StatusLine status = response.getStatusLine();
int code = status.getStatusCode();
// TODO the client doesn't handle redirects for posts; should we do that here?
if (code >= SUCCESS_MIN && code <= SUCCESS_MAX) {
return response;
} else {
throw new SparqlException("Unexpected status code in server response: " +
status.getReasonPhrase() + "(" + code + ")");
}
} catch (UnsupportedEncodingException e) {
throw new SparqlException("Unabled to encode data", e);
} catch (ClientProtocolException cpe) {
throw new SparqlException("Error in protocol", cpe);
} catch (IOException e) {
throw new SparqlException(e);
}
}