use of org.eclipse.rdf4j.RDF4JException in project rdf4j by eclipse.
the class RDF4JProtocolSession method getNamespace.
public String getNamespace(String prefix) throws IOException, RepositoryException, UnauthorizedException {
checkRepositoryURL();
HttpGet method = new HttpGet(Protocol.getNamespacePrefixLocation(getQueryURL(), prefix));
try {
HttpResponse response = execute(method);
int code = response.getStatusLine().getStatusCode();
if (code == HttpURLConnection.HTTP_OK || code == HttpURLConnection.HTTP_NOT_AUTHORITATIVE) {
return EntityUtils.toString(response.getEntity());
} else {
EntityUtils.consume(response.getEntity());
return null;
}
} catch (RepositoryException e) {
throw e;
} catch (RDF4JException e) {
throw new RepositoryException(e);
} finally {
method.reset();
}
}
use of org.eclipse.rdf4j.RDF4JException in project rdf4j by eclipse.
the class RDF4JProtocolSession method clearNamespaces.
public void clearNamespaces() throws IOException, RepositoryException, UnauthorizedException {
checkRepositoryURL();
HttpDelete method = new HttpDelete(Protocol.getNamespacesLocation(getQueryURL()));
try {
executeNoContent(method);
} catch (RepositoryException e) {
throw e;
} catch (RDF4JException e) {
throw new RepositoryException(e);
} finally {
method.reset();
}
}
use of org.eclipse.rdf4j.RDF4JException 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.RDF4JException 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.RDF4JException in project rdf4j by eclipse.
the class SPARQLProtocolSession method sendGraphQueryViaHttp.
private HttpResponse sendGraphQueryViaHttp(HttpUriRequest method, boolean requireContext, Set<RDFFormat> rdfFormats) throws RepositoryException, IOException, QueryInterruptedException, MalformedQueryException {
List<String> acceptParams = RDFFormat.getAcceptParams(rdfFormats, requireContext, getPreferredRDFFormat());
method.addHeader(ACCEPT_PARAM_NAME, String.join(", ", acceptParams));
try {
return executeOK(method);
} catch (RepositoryException | MalformedQueryException | QueryInterruptedException e) {
throw e;
} catch (RDF4JException e) {
throw new RepositoryException(e);
}
}
Aggregations