Search in sources :

Example 1 with ErrorInfo

use of org.eclipse.rdf4j.http.protocol.error.ErrorInfo 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 ErrorInfo

use of org.eclipse.rdf4j.http.protocol.error.ErrorInfo in project rdf4j by eclipse.

the class SPARQLProtocolSession method getErrorInfo.

protected ErrorInfo getErrorInfo(HttpResponse response) throws RepositoryException {
    try {
        ErrorInfo errInfo = ErrorInfo.parse(EntityUtils.toString(response.getEntity()));
        logger.warn("Server reports problem: {}", errInfo.getErrorMessage());
        return errInfo;
    } catch (IOException e) {
        logger.warn("Unable to retrieve error info from server");
        throw new RepositoryException("Unable to retrieve error info from server", e);
    }
}
Also used : ErrorInfo(org.eclipse.rdf4j.http.protocol.error.ErrorInfo) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException)

Aggregations

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