Search in sources :

Example 1 with QueryInterruptedException

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());
        }
    }
}
Also used : UnsupportedRDFormatException(org.eclipse.rdf4j.rio.UnsupportedRDFormatException) ErrorInfo(org.eclipse.rdf4j.http.protocol.error.ErrorInfo) UnauthorizedException(org.eclipse.rdf4j.http.protocol.UnauthorizedException) HttpResponse(org.apache.http.HttpResponse) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) UnsupportedQueryLanguageException(org.eclipse.rdf4j.query.UnsupportedQueryLanguageException) QueryInterruptedException(org.eclipse.rdf4j.query.QueryInterruptedException) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Example 2 with QueryInterruptedException

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);
    }
}
Also used : QueryResultFormat(org.eclipse.rdf4j.query.resultio.QueryResultFormat) BooleanQueryResultFormat(org.eclipse.rdf4j.query.resultio.BooleanQueryResultFormat) TupleQueryResultFormat(org.eclipse.rdf4j.query.resultio.TupleQueryResultFormat) ArrayList(java.util.ArrayList) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) RDF4JException(org.eclipse.rdf4j.RDF4JException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) QueryInterruptedException(org.eclipse.rdf4j.query.QueryInterruptedException)

Example 3 with QueryInterruptedException

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);
    }
}
Also used : SPARQLProtocolSession(org.eclipse.rdf4j.http.client.SPARQLProtocolSession) UnauthorizedException(org.eclipse.rdf4j.http.protocol.UnauthorizedException) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException) QueryInterruptedException(org.eclipse.rdf4j.query.QueryInterruptedException)

Example 4 with QueryInterruptedException

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);
    }
}
Also used : MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) RDF4JException(org.eclipse.rdf4j.RDF4JException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) QueryInterruptedException(org.eclipse.rdf4j.query.QueryInterruptedException)

Aggregations

MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)4 QueryInterruptedException (org.eclipse.rdf4j.query.QueryInterruptedException)4 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)4 RDF4JException (org.eclipse.rdf4j.RDF4JException)2 UnauthorizedException (org.eclipse.rdf4j.http.protocol.UnauthorizedException)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HttpResponse (org.apache.http.HttpResponse)1 SPARQLProtocolSession (org.eclipse.rdf4j.http.client.SPARQLProtocolSession)1 ErrorInfo (org.eclipse.rdf4j.http.protocol.error.ErrorInfo)1 UnsupportedQueryLanguageException (org.eclipse.rdf4j.query.UnsupportedQueryLanguageException)1 BooleanQueryResultFormat (org.eclipse.rdf4j.query.resultio.BooleanQueryResultFormat)1 QueryResultFormat (org.eclipse.rdf4j.query.resultio.QueryResultFormat)1 TupleQueryResultFormat (org.eclipse.rdf4j.query.resultio.TupleQueryResultFormat)1 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)1 UnsupportedRDFormatException (org.eclipse.rdf4j.rio.UnsupportedRDFormatException)1