Search in sources :

Example 6 with RDF4JException

use of org.eclipse.rdf4j.RDF4JException 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 7 with RDF4JException

use of org.eclipse.rdf4j.RDF4JException in project rdf4j by eclipse.

the class HTTPRepositoryConnection method rollback.

public void rollback() throws RepositoryException {
    if (this.getRepository().useCompatibleMode()) {
        txn.clear();
        active = false;
        return;
    }
    flushTransactionState(Action.ROLLBACK);
    try {
        client.rollbackTransaction();
        active = false;
    } catch (RDF4JException e) {
        throw new RepositoryException(e);
    } catch (IllegalStateException e) {
        throw new RepositoryException(e);
    } catch (IOException e) {
        throw new RepositoryException(e);
    }
}
Also used : RDF4JException(org.eclipse.rdf4j.RDF4JException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException)

Example 8 with RDF4JException

use of org.eclipse.rdf4j.RDF4JException in project rdf4j by eclipse.

the class HTTPRepositoryConnection method commit.

public void commit() throws RepositoryException {
    if (this.getRepository().useCompatibleMode()) {
        synchronized (txn) {
            if (txn.size() > 0) {
                try {
                    client.sendTransaction(txn);
                    txn.clear();
                } catch (IOException e) {
                    throw new RepositoryException(e);
                }
            }
            active = false;
        }
        return;
    }
    flushTransactionState(Action.COMMIT);
    try {
        client.commitTransaction();
        active = false;
    } catch (RDF4JException e) {
        throw new RepositoryException(e);
    } catch (IllegalStateException e) {
        throw new RepositoryException(e);
    } catch (IOException e) {
        throw new RepositoryException(e);
    }
}
Also used : RDF4JException(org.eclipse.rdf4j.RDF4JException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException) IOException(java.io.IOException)

Example 9 with RDF4JException

use of org.eclipse.rdf4j.RDF4JException in project nanopub-server by tkuhn.

the class NanopubDb method getNanopub.

public Nanopub getNanopub(String artifactCode) {
    BasicDBObject query = new BasicDBObject("_id", artifactCode);
    DBCursor cursor = getNanopubCollection().find(query);
    if (!cursor.hasNext()) {
        return null;
    }
    String nanopubString = cursor.next().get("nanopub").toString();
    Nanopub np = null;
    try {
        np = new NanopubImpl(nanopubString, internalFormat);
    } catch (MalformedNanopubException ex) {
        throw new RuntimeException("Stored nanopub is not wellformed (this shouldn't happen)", ex);
    } catch (RDF4JException ex) {
        throw new RuntimeException("Stored nanopub is corrupted (this shouldn't happen)", ex);
    }
    if (ServerConf.get().isCheckNanopubsOnGetEnabled() && !TrustyNanopubUtils.isValidTrustyNanopub(np)) {
        throw new RuntimeException("Stored nanopub is not trusty (this shouldn't happen)");
    }
    return np;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) DBCursor(com.mongodb.DBCursor) Nanopub(org.nanopub.Nanopub) RDF4JException(org.eclipse.rdf4j.RDF4JException) MalformedNanopubException(org.nanopub.MalformedNanopubException) NanopubImpl(org.nanopub.NanopubImpl)

Example 10 with RDF4JException

use of org.eclipse.rdf4j.RDF4JException in project rdf4j by eclipse.

the class RDF4JProtocolSession method removeNamespacePrefix.

public void removeNamespacePrefix(String prefix) throws IOException, RepositoryException, UnauthorizedException {
    checkRepositoryURL();
    HttpDelete method = new HttpDelete(Protocol.getNamespacePrefixLocation(getQueryURL(), prefix));
    try {
        executeNoContent(method);
    } catch (RepositoryException e) {
        throw e;
    } catch (RDF4JException e) {
        throw new RepositoryException(e);
    } finally {
        method.reset();
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) RDF4JException(org.eclipse.rdf4j.RDF4JException) RepositoryException(org.eclipse.rdf4j.repository.RepositoryException)

Aggregations

RDF4JException (org.eclipse.rdf4j.RDF4JException)16 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)13 IOException (java.io.IOException)4 HttpGet (org.apache.http.client.methods.HttpGet)3 HttpPut (org.apache.http.client.methods.HttpPut)3 URISyntaxException (java.net.URISyntaxException)2 HttpDelete (org.apache.http.client.methods.HttpDelete)2 HttpPost (org.apache.http.client.methods.HttpPost)2 URIBuilder (org.apache.http.client.utils.URIBuilder)2 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)2 QueryInterruptedException (org.eclipse.rdf4j.query.QueryInterruptedException)2 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)2 BasicDBObject (com.mongodb.BasicDBObject)1 DBCursor (com.mongodb.DBCursor)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1