I have following code to create a local SailRepository for GraphDB:
//Create local repo
repositoryManager = new LocalRepositoryManager(baseDir);
repositoryManager.init();
if (repositoryManager.hasRepositoryConfig("test"))
throw new RuntimeException("Repository evalGraphDB already exists.");
InputStream config = TestRDFStarTimestampingPlugin.class.getResourceAsStream("/repo-defaults.ttl");
Model repo_config_graph = Rio.parse(config, "", RDFFormat.TURTLE);
Resource repositoryNode = Models.subject(repo_config_graph.filter(null, RDF.TYPE, RepositoryConfigSchema.REPOSITORY)).orElse(null);
repo_config_graph.add(repositoryNode, RepositoryConfigSchema.REPOSITORYID,
SimpleValueFactory.getInstance().createLiteral("test"));
RepositoryConfig repositoryConfig = RepositoryConfig.create(repo_config_graph, repositoryNode);
repositoryManager.addRepositoryConfig(repositoryConfig);
//Initialize repo
SailRepository repo = (SailRepository)
repositoryManager.getRepository("test");
repo.init();
Now I want to use a SPARQLRepository object to query against the endpoint configured in the repo-defaults.ttl:
repo = new SPARQLRepository("http://localhost:7200/repositories/test/statements");
try (RepositoryConnection connection = repo.getConnection()) {
repo.init();
connection.begin();
connection.prepareUpdate(updateString).execute();
connection.commit();
}
My connetion to this repository gets refused
Exception in thread "Thread-108" org.eclipse.rdf4j.query.UpdateExecutionException: Connect to localhost:7200 [localhost/127.0.0.1] failed: Connection refused (Connection refused)
and it is probably because the SailRepository object does not have a HttpClient or something the like. I saw there are possibilities to create a HttpClientSessionManager() with repo.setHttpClientSessionManager(); but then I need to implement all the protocols. Is there e.g. a factory that I can use to create a SPARQLProtocolSession or can I add some further configurations to the repo-defaults.ttl? My repo-defaults.ttl looks like the code provided here: https://graphdb.ontotext.com/documentation/free/configuring-a-repository.html My post endpoint in repo-defaults.ttl is: http://localhost:7200/repositories/test/statements
I am kindly asking for help. Thank you!
UPDATE: My repo-defaults.ttl file looks like this:
# RDF4J configuration template for a GraphDB Free repository
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix rep: <http://www.openrdf.org/config/repository#>.
@prefix sr: <http://www.openrdf.org/config/repository/sail#>.
@prefix sail: <http://www.openrdf.org/config/sail#>.
@prefix owlim: <http://www.ontotext.com/trree/owlim#>.
@prefix sparql: <http://www.openrdf.org/config/repository/sparql#>.
[] a rep:Repository ;
rep:repositoryID "test" ;
rdfs:label "Repository for evaluation of Sparql* queries against GraphDB" ;
rep:repositoryImpl [
rep:repositoryType "graphdb:FreeSailRepository" ;
sparql:query-endpoint <http://localhost:7200/repositories/test> ;
sparql:update-endpoint <http://localhost:7200/repositories/test/statements> ;
sr:sailImpl [
sail:sailType "graphdb:FreeSail" ;
owlim:base-URL "http://example.org/graphdb#" ;
owlim:defaultNS "" ;
owlim:entity-index-size "10000000" ;
owlim:entity-id-size "32" ;
owlim:imports "" ;
owlim:repository-type "file-repository" ;
owlim:ruleset "rdfsplus-optimized" ;
owlim:storage-folder "storage" ;
owlim:enable-context-index "false" ;
owlim:enablePredicateList "true" ;
owlim:in-memory-literal-properties "true" ;
owlim:enable-literal-index "true" ;
owlim:check-for-inconsistencies "false" ;
owlim:disable-sameAs "false" ;
owlim:query-timeout "0" ;
owlim:query-limit-results "0" ;
owlim:throw-QueryEvaluationException-on-timeout "false" ;
owlim:read-only "false" ;
owlim:nonInterpretablePredicates "http://www.w3.org/2000/01/rdf-schema#label;http://www.w3.org/1999/02/22-rdf-syntax-ns#type;http://www.ontotext.com/owlim/ces#gazetteerConfig;http://www.ontotext.com/owlim/ces#metadataConfig" ;
]
].
But the output config.ttl file in the target folder does not have the sparql endpoints anymore:
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rep: <http://www.openrdf.org/config/repository#> .
@prefix sail: <http://www.openrdf.org/config/sail#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<#test> a rep:Repository;
rep:repositoryID "test";
rep:repositoryImpl [
rep:repositoryType "graphdb:FreeSailRepository";
<http://www.openrdf.org/config/repository/sail#sailImpl> [
<http://www.ontotext.com/trree/owlim#base-URL> "http://example.org/graphdb#";
<http://www.ontotext.com/trree/owlim#check-for-inconsistencies> "false";
<http://www.ontotext.com/trree/owlim#defaultNS> "";
<http://www.ontotext.com/trree/owlim#disable-sameAs> "false";
<http://www.ontotext.com/trree/owlim#enable-context-index> "false";
<http://www.ontotext.com/trree/owlim#enable-literal-index> "true";
<http://www.ontotext.com/trree/owlim#enablePredicateList> "true";
<http://www.ontotext.com/trree/owlim#entity-id-size> "32";
<http://www.ontotext.com/trree/owlim#entity-index-size> "10000000";
<http://www.ontotext.com/trree/owlim#imports> "";
<http://www.ontotext.com/trree/owlim#in-memory-literal-properties> "true";
<http://www.ontotext.com/trree/owlim#nonInterpretablePredicates> "http://www.w3.org/2000/01/rdf-schema#label;http://www.w3.org/1999/02/22-rdf-syntax-ns#type;http://www.ontotext.com/owlim/ces#gazetteerConfig;http://www.ontotext.com/owlim/ces#metadataConfig";
<http://www.ontotext.com/trree/owlim#query-limit-results> "0";
<http://www.ontotext.com/trree/owlim#query-timeout> "0";
<http://www.ontotext.com/trree/owlim#read-only> "false";
<http://www.ontotext.com/trree/owlim#repository-type> "file-repository";
<http://www.ontotext.com/trree/owlim#ruleset> "rdfsplus-optimized";
<http://www.ontotext.com/trree/owlim#storage-folder> "storage";
<http://www.ontotext.com/trree/owlim#throw-QueryEvaluationException-on-timeout> "false";
sail:sailType "graphdb:FreeSail"
]
];
rdfs:label "Repository for evaluation of Sparql* queries against GraphDB" .
Might this be an issue?