Search in sources :

Example 1 with RepositoryConnectionWrapper

use of org.eclipse.rdf4j.repository.base.RepositoryConnectionWrapper in project inception by inception-project.

the class KnowledgeBaseServiceImpl method getConnection.

@Override
public RepositoryConnection getConnection(KnowledgeBase kb) {
    assertRegistration(kb);
    Repository repo = repoManager.getRepository(kb.getRepositoryId());
    if (repo instanceof SPARQLRepository) {
        SPARQLRepositoryConfig sparqlRepoConfig = (SPARQLRepositoryConfig) getKnowledgeBaseConfig(kb);
        URI uri = URI.create(sparqlRepoConfig.getQueryEndpointUrl());
        String userInfo = uri.getUserInfo();
        if (StringUtils.isNotBlank(userInfo)) {
            userInfo = userInfo.trim();
            String username;
            String password;
            if (userInfo.contains(":")) {
                username = substringBefore(userInfo, ":");
                password = substringAfter(userInfo, ":");
            } else {
                username = userInfo;
                password = "";
            }
            SPARQLRepository sparqlRepo = (SPARQLRepository) repo;
            sparqlRepo.setUsernameAndPassword(username, password);
        }
    }
    return new RepositoryConnectionWrapper(repo, repo.getConnection()) {

        {
            skipCertificateChecks(kb.isSkipSslValidation());
        }

        @Override
        public void close() throws RepositoryException {
            try {
                super.close();
            } finally {
                restoreSslVerification();
            }
        }
    };
}
Also used : SPARQLRepositoryConfig(org.eclipse.rdf4j.repository.sparql.config.SPARQLRepositoryConfig) SailRepository(org.eclipse.rdf4j.repository.sail.SailRepository) SPARQLRepository(org.eclipse.rdf4j.repository.sparql.SPARQLRepository) Repository(org.eclipse.rdf4j.repository.Repository) SPARQLRepository(org.eclipse.rdf4j.repository.sparql.SPARQLRepository) RepositoryConnectionWrapper(org.eclipse.rdf4j.repository.base.RepositoryConnectionWrapper) URI(java.net.URI)

Aggregations

URI (java.net.URI)1 Repository (org.eclipse.rdf4j.repository.Repository)1 RepositoryConnectionWrapper (org.eclipse.rdf4j.repository.base.RepositoryConnectionWrapper)1 SailRepository (org.eclipse.rdf4j.repository.sail.SailRepository)1 SPARQLRepository (org.eclipse.rdf4j.repository.sparql.SPARQLRepository)1 SPARQLRepositoryConfig (org.eclipse.rdf4j.repository.sparql.config.SPARQLRepositoryConfig)1