use of org.eclipse.rdf4j.http.client.RDF4JProtocolSession in project rdf4j by eclipse.
the class RemoteRepositoryManager method addRepositoryConfig.
@Override
public void addRepositoryConfig(RepositoryConfig config) throws RepositoryException, RepositoryConfigException {
try (RDF4JProtocolSession httpClient = getSesameClient().createRDF4JProtocolSession(serverURL)) {
String baseURI = Protocol.getRepositoryLocation(serverURL, config.getID());
Resource ctx = SimpleValueFactory.getInstance().createIRI(baseURI + "#" + config.getID());
httpClient.setUsernameAndPassword(username, password);
httpClient.setRepository(Protocol.getRepositoryLocation(serverURL, SystemRepository.ID));
Model model = new LinkedHashModel();
config.export(model, ctx);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Rio.write(model, baos, httpClient.getPreferredRDFFormat());
removeRepository(config.getID());
try (InputStream contents = new ByteArrayInputStream(baos.toByteArray())) {
httpClient.upload(contents, baseURI, httpClient.getPreferredRDFFormat(), false, true, ctx);
}
} catch (IOException | QueryEvaluationException | UnauthorizedException ue) {
throw new RepositoryException(ue);
}
}
use of org.eclipse.rdf4j.http.client.RDF4JProtocolSession in project rdf4j by eclipse.
the class RemoteRepositoryManager method removeRepository.
@Override
public boolean removeRepository(String repositoryID) throws RepositoryException, RepositoryConfigException {
boolean existingRepo = hasRepositoryConfig(repositoryID);
if (existingRepo) {
try (RDF4JProtocolSession httpClient = getSesameClient().createRDF4JProtocolSession(serverURL)) {
httpClient.setUsernameAndPassword(username, password);
httpClient.deleteRepository(repositoryID);
} catch (IOException e) {
logger.warn("error while deleting remote repository", e);
throw new RepositoryConfigException(e);
}
}
return existingRepo;
}
Aggregations