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);
}
}
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);
}
}
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);
}
}
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;
}
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();
}
}
Aggregations