Search in sources :

Example 1 with UnsupportedQueryLanguageException

use of org.eclipse.rdf4j.query.UnsupportedQueryLanguageException 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)

Aggregations

HttpResponse (org.apache.http.HttpResponse)1 UnauthorizedException (org.eclipse.rdf4j.http.protocol.UnauthorizedException)1 ErrorInfo (org.eclipse.rdf4j.http.protocol.error.ErrorInfo)1 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)1 QueryInterruptedException (org.eclipse.rdf4j.query.QueryInterruptedException)1 UnsupportedQueryLanguageException (org.eclipse.rdf4j.query.UnsupportedQueryLanguageException)1 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)1 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)1 UnsupportedRDFormatException (org.eclipse.rdf4j.rio.UnsupportedRDFormatException)1