0

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?

Greenfish
  • 358
  • 2
  • 5
  • 19
  • The code for accessing a sparql endpoint should work fine as is. The error means it can't reach your graphdb server. I'd check that your server is running normally. – Jeen Broekstra Mar 11 '22 at 18:29
  • The server is running normally. I can access it with repo.getConnection().prepareUpdate(updateString).execute(); However, this is a SailRepositoryConnection but with a RepositoryConnection it does not work – Greenfish Mar 14 '22 at 10:16
  • Can it be that my embedded server is terminating and that's why it can't be reached? – Greenfish Mar 14 '22 at 10:23
  • I checked the httpclient with assertNotNull(repo.getHttpClient()); and the assertion fails – Greenfish Mar 14 '22 at 10:46
  • I don't know why your server isn't running, as you haven't shown how you start it, but yeah I'd look at that. Btw just to be clear: creating a Sailrepository does not start a server. – Jeen Broekstra Mar 14 '22 at 18:26
  • I havent started any server manually. The idea was to automatically start a graphdb server and connect to the repository. I thought that using a repository config file and a repository manager might do the trick. – Greenfish Mar 14 '22 at 22:09
  • Unfortunately it's not quite that simple. I suggest you have a look at the GraphDB install instructions, it tells you about the options for configuring and starting a server. – Jeen Broekstra Mar 15 '22 at 07:33
  • I figured out what the issue is. I thought that I can start the server + repository with Sail. But sail is just the "repository part" and I need to start the GraphDB server first, either manually or through a docker image and then built the SailRepositry into GraphDB's data directory, which is on ~/.graphdb/data. – Greenfish Mar 15 '22 at 10:42

0 Answers0