use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.
the class RDF4JProtocolSession method setNamespacePrefix.
public void setNamespacePrefix(String prefix, String name) throws IOException, RepositoryException, UnauthorizedException {
checkRepositoryURL();
HttpPut method = new HttpPut(Protocol.getNamespacePrefixLocation(getQueryURL(), prefix));
try {
method.setEntity(new StringEntity(name, ContentType.create("text/plain", "UTF-8")));
executeNoContent(method);
} catch (RepositoryException e) {
throw e;
} catch (RDF4JException e) {
throw new RepositoryException(e);
} finally {
method.reset();
}
}
use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.
the class RDF4JProtocolSession method getNamespaces.
public void getNamespaces(TupleQueryResultHandler handler) throws IOException, TupleQueryResultHandlerException, RepositoryException, UnauthorizedException, QueryInterruptedException {
checkRepositoryURL();
HttpGet method = new HttpGet(Protocol.getNamespacesLocation(getQueryURL()));
try {
getTupleQueryResult(method, handler);
} catch (MalformedQueryException e) {
logger.warn("Server reported unexpected malfored query error", e);
throw new RepositoryException(e.getMessage(), e);
} finally {
method.reset();
}
}
use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.
the class RDF4JProtocolSession method beginTransaction.
public synchronized void beginTransaction(IsolationLevel isolationLevel) throws RDF4JException, IOException, UnauthorizedException {
checkRepositoryURL();
if (transactionURL != null) {
throw new IllegalStateException("Transaction URL is already set");
}
HttpPost method = new HttpPost(Protocol.getTransactionsLocation(getRepositoryURL()));
try {
method.setHeader("Content-Type", Protocol.FORM_MIME_TYPE + "; charset=utf-8");
List<NameValuePair> params = new ArrayList<NameValuePair>();
if (isolationLevel != null) {
params.add(new BasicNameValuePair(Protocol.ISOLATION_LEVEL_PARAM_NAME, isolationLevel.getURI().stringValue()));
}
method.setEntity(new UrlEncodedFormEntity(params, UTF8));
HttpResponse response = execute(method);
try {
int code = response.getStatusLine().getStatusCode();
if (code == HttpURLConnection.HTTP_CREATED) {
transactionURL = response.getFirstHeader("Location").getValue();
if (transactionURL == null) {
throw new RepositoryException("no valid transaction ID received in server response.");
} else {
pingTransaction();
}
} else {
throw new RepositoryException("unable to start transaction. HTTP error code " + code);
}
} finally {
EntityUtils.consume(response.getEntity());
}
} finally {
method.reset();
}
}
use of org.eclipse.rdf4j.repository.RepositoryException in project rdf4j by eclipse.
the class RDF4JProtocolSession method size.
/*-------------------------*
* Repository/context size *
*-------------------------*/
public long size(Resource... contexts) throws IOException, RepositoryException, UnauthorizedException {
checkRepositoryURL();
try {
String transactionURL = getTransactionURL();
final boolean useTransaction = transactionURL != null;
String baseLocation = useTransaction ? appendAction(transactionURL, Action.SIZE) : Protocol.getSizeLocation(getQueryURL());
URIBuilder url = new URIBuilder(baseLocation);
String[] encodedContexts = Protocol.encodeContexts(contexts);
for (int i = 0; i < encodedContexts.length; i++) {
url.addParameter(Protocol.CONTEXT_PARAM_NAME, encodedContexts[i]);
}
final HttpRequestBase method = useTransaction ? new HttpPut(url.build()) : new HttpGet(url.build());
try {
String response = EntityUtils.toString(executeOK(method).getEntity());
pingTransaction();
try {
return Long.parseLong(response);
} catch (NumberFormatException e) {
throw new RepositoryException("Server responded with invalid size value: " + response);
}
} finally {
method.reset();
}
} catch (URISyntaxException e) {
throw new AssertionError(e);
} catch (RepositoryException e) {
throw e;
} catch (RDF4JException e) {
throw new RepositoryException(e);
}
}
use of org.eclipse.rdf4j.repository.RepositoryException 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);
}
}
Aggregations