use of org.eclipse.rdf4j.query.QueryInterruptedException in project rdf4j by eclipse.
the class SPARQLProtocolSession method execute.
protected HttpResponse execute(HttpUriRequest method) throws IOException, RDF4JException {
boolean consume = true;
if (params != null) {
method.setParams(params);
}
HttpResponse response = httpClient.execute(method, httpContext);
try {
int httpCode = response.getStatusLine().getStatusCode();
if (httpCode >= 200 && httpCode < 300 || httpCode == HttpURLConnection.HTTP_NOT_FOUND) {
consume = false;
// everything OK, control flow can continue
return response;
} else {
switch(httpCode) {
case // 401
HttpURLConnection.HTTP_UNAUTHORIZED:
throw new UnauthorizedException();
case // 503
HttpURLConnection.HTTP_UNAVAILABLE:
throw new QueryInterruptedException();
default:
ErrorInfo errInfo = getErrorInfo(response);
// Throw appropriate exception
if (errInfo.getErrorType() == ErrorType.MALFORMED_DATA) {
throw new RDFParseException(errInfo.getErrorMessage());
} else if (errInfo.getErrorType() == ErrorType.UNSUPPORTED_FILE_FORMAT) {
throw new UnsupportedRDFormatException(errInfo.getErrorMessage());
} else if (errInfo.getErrorType() == ErrorType.MALFORMED_QUERY) {
throw new MalformedQueryException(errInfo.getErrorMessage());
} else if (errInfo.getErrorType() == ErrorType.UNSUPPORTED_QUERY_LANGUAGE) {
throw new UnsupportedQueryLanguageException(errInfo.getErrorMessage());
} else if (errInfo.toString().length() > 0) {
throw new RepositoryException(errInfo.toString());
} else {
throw new RepositoryException(response.getStatusLine().getReasonPhrase());
}
}
}
} finally {
if (consume) {
EntityUtils.consumeQuietly(response.getEntity());
}
}
}
use of org.eclipse.rdf4j.query.QueryInterruptedException in project rdf4j by eclipse.
the class SPARQLProtocolSession method sendTupleQueryViaHttp.
/**
* Send the tuple query via HTTP and throws an exception in case anything goes wrong, i.e. only for HTTP
* 200 the method returns without exception. If HTTP status code is not equal to 200, the request is
* aborted, however pooled connections are not released.
*
* @param method
* @throws RepositoryException
* @throws HttpException
* @throws IOException
* @throws QueryInterruptedException
* @throws MalformedQueryException
*/
private HttpResponse sendTupleQueryViaHttp(HttpUriRequest method, Set<QueryResultFormat> tqrFormats) throws RepositoryException, IOException, QueryInterruptedException, MalformedQueryException {
final List<String> acceptValues = new ArrayList<String>(tqrFormats.size());
for (QueryResultFormat format : tqrFormats) {
// Determine a q-value that reflects the user specified preference
int qValue = 10;
if (preferredTQRFormat != null && !preferredTQRFormat.equals(format)) {
// Prefer specified format over other formats
qValue -= 2;
}
for (String mimeType : format.getMIMETypes()) {
String acceptParam = mimeType;
if (qValue < 10) {
acceptParam += ";q=0." + qValue;
}
acceptValues.add(acceptParam);
}
}
method.addHeader(ACCEPT_PARAM_NAME, String.join(", ", acceptValues));
try {
return executeOK(method);
} catch (RepositoryException | MalformedQueryException | QueryInterruptedException e) {
throw e;
} catch (RDF4JException e) {
throw new RepositoryException(e);
}
}
use of org.eclipse.rdf4j.query.QueryInterruptedException in project rdf4j by eclipse.
the class HTTPUpdate method execute.
@Override
public void execute() throws UpdateExecutionException {
try {
if (httpCon.getRepository().useCompatibleMode()) {
if (httpCon.isAutoCommit()) {
// execute update immediately
SPARQLProtocolSession client = getHttpClient();
try {
client.sendUpdate(getQueryLanguage(), getQueryString(), getBaseURI(), dataset, includeInferred, getMaxExecutionTime(), getBindingsArray());
} catch (UnauthorizedException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
} catch (QueryInterruptedException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
} catch (MalformedQueryException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
} catch (IOException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
}
} else {
// defer execution as part of transaction.
httpCon.scheduleUpdate(this);
}
return;
}
SPARQLProtocolSession client = getHttpClient();
try {
httpCon.flushTransactionState(Action.UPDATE);
client.sendUpdate(getQueryLanguage(), getQueryString(), getBaseURI(), dataset, includeInferred, getMaxExecutionTime(), getBindingsArray());
} catch (UnauthorizedException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
} catch (QueryInterruptedException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
} catch (MalformedQueryException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
} catch (IOException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
}
} catch (RepositoryException e) {
throw new HTTPUpdateExecutionException(e.getMessage(), e);
}
}
use of org.eclipse.rdf4j.query.QueryInterruptedException in project rdf4j by eclipse.
the class SPARQLProtocolSession method sendGraphQueryViaHttp.
private HttpResponse sendGraphQueryViaHttp(HttpUriRequest method, boolean requireContext, Set<RDFFormat> rdfFormats) throws RepositoryException, IOException, QueryInterruptedException, MalformedQueryException {
List<String> acceptParams = RDFFormat.getAcceptParams(rdfFormats, requireContext, getPreferredRDFFormat());
method.addHeader(ACCEPT_PARAM_NAME, String.join(", ", acceptParams));
try {
return executeOK(method);
} catch (RepositoryException | MalformedQueryException | QueryInterruptedException e) {
throw e;
} catch (RDF4JException e) {
throw new RepositoryException(e);
}
}
Aggregations