org.apache.jena.fuseki.main.FusekiServer Java Examples
The following examples show how to use
org.apache.jena.fuseki.main.FusekiServer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SparqlJenaEngineTest.java From zeppelin with Apache License 2.0 | 7 votes |
@BeforeClass public static void setUp() { port = Fuseki.choosePort(); Model model = ModelFactory.createDefaultModel(); model.read(DATA_FILE); Dataset ds = DatasetFactory.create(model); server = FusekiServer .create() .port(port) .add(DATASET, ds) .build(); DataAccessPointRegistry registry = server.getDataAccessPointRegistry(); assertTrue(registry.isRegistered(DATASET)); assertEquals(1, registry.size()); server.start(); }
Example #2
Source File: SparqlDataSourceTest.java From Server.Java with MIT License | 6 votes |
/** * * @throws Exception */ @BeforeClass public static void setUpClass() throws Exception { final String typeName = "SparqlSourceType"; if ( ! DataSourceTypesRegistry.isRegistered(typeName) ) { DataSourceTypesRegistry.register( typeName, new SparqlDataSourceType() ); } String tmpdir = System.getProperty("java.io.tmpdir"); jena = new File(tmpdir, "ldf-sparql-test"); jena.mkdir(); dataset = TDBFactory.createDataset(jena.getAbsolutePath()); Model model = dataset.getDefaultModel(); InputStream in = ClassLoader.getSystemResourceAsStream("demo.nt"); RDFDataMgr.read(model, in, Lang.NTRIPLES); // Dynamically-generated port comes from pom.xml configuration: build-helper-maven-plugin int fusekiPort = Integer.parseInt(System.getProperty("fuseki.port")); // Create Fuseki, loaded with the test dataset fuseki = FusekiServer.create().setPort(fusekiPort).add("/ds", dataset).build(); fuseki.start(); // Everything is in place, now create the LDF datasource JsonObject config = createConfig("sparql test", "sparql test", typeName); JsonObject settings = new JsonObject(); settings.addProperty("endpoint", "http://localhost:" + fusekiPort + "/ds"); config.add("settings", settings); setDatasource(DataSourceFactory.create(config)); }
Example #3
Source File: Matrix.java From rdf-delta with Apache License 2.0 | 6 votes |
private static void setupFuseki(int fusekiPort, String dsName, String zoneDir, DeltaLink deltaLink) { //deltaLink.register(Id.create()); FileOps.ensureDir(zoneDir); FileOps.clearAll(zoneDir); DeltaClient dClient = setup_dataset(dsName, zoneDir, deltaLink); Zone zone = dClient.getZone(); DataSourceDescription dsd = deltaLink.getDataSourceDescriptionByName(dsName); Id dsRef = dsd.getId(); SyncPolicy syncPolicy = SyncPolicy.TXN_RW; LocalStorageType storage = LocalStorageType.MEM; dClient.register(dsRef, storage, syncPolicy); DeltaConnection deltaConnection = dClient.getLocal(dsRef); DatasetGraph dsg = deltaConnection.getDatasetGraph(); FusekiServer server = FusekiServer.create() .loopback(true) .port(fusekiPort) .add(dsName, dsg) .build(); server.start(); }
Example #4
Source File: TestPatchFuseki.java From rdf-delta with Apache License 2.0 | 6 votes |
@Test public void apply_1() { Pair<FusekiServer, DatasetGraph> p = create(); FusekiServer server = p.getLeft(); DatasetGraph dsg = p.getRight(); server.start(); String url = "http://localhost:"+server.getPort()+"/"; try { assertFalse(dsg.contains(node(":g"), node(":s"), node(":p"), node(":o"))); // Service name applyPatch(url+"/ds/patch", patch1()); assertTrue(dsg.contains(node(":g"), node(":s"), node(":p"), node(":o"))); // Content type. applyPatch(url+"/ds", patch2()); assertFalse(dsg.contains(node(":g"), node(":s"), node(":p"), node(":o"))); applyPatch(url+"/ds", patch1()); assertTrue(dsg.contains(node(":g"), node(":s"), node(":p"), node(":o"))); } finally { server.stop(); } }
Example #5
Source File: DeltaEx03_FusekiLogChanges.java From rdf-delta with Apache License 2.0 | 6 votes |
public static void main2(String ...args) { int PORT = 2020; DatasetGraph dsgBase = DatasetGraphFactory.createTxnMem(); RDFChanges changeLog = RDFPatchOps.textWriter(System.out); DatasetGraph dsg = RDFPatchOps.changes(dsgBase, changeLog); // Create a server with the changes-enables dataset. // Plain server. No other registration necessary. FusekiServer server = FusekiServer.create() .port(PORT) .add("/ds", dsg) .build(); server.start(); RDFConnection conn = RDFConnectionFactory.connect("http://localhost:"+PORT+"/ds"); UpdateRequest update = UpdateFactory.create("PREFIX : <http://example/> INSERT DATA { :s :p 123 }"); // Note - no prefix in changes. The SPARQL Update prefix is not a chnage to the dataset prefixes. conn.update(update); server.stop(); // // Server in the background so explicitly exit. // System.exit(0); }
Example #6
Source File: TestDeltaFusekiBad.java From rdf-delta with Apache License 2.0 | 6 votes |
@Test public void fuseki_stop_start() { DeltaServer deltaServer = deltaServer(); FusekiServer server1 = fuseki1(); try { server1.stop(); RDFConnection conn1 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+ds1) ; QueryExecution qExec = conn1.query("ASK{}"); try { qExec.execAsk(); fail(); } catch(QueryExceptionHTTP ex) {} // Restart, same port. server1 = fuseki1(Start.RESTART); QueryExecution qExec1 = conn1.query("ASK{}"); qExec1.execAsk(); } finally { server1.stop(); deltaServer.stop(); } }
Example #7
Source File: DeltaEx06_LocalDatasetToFuseki.java From rdf-delta with Apache License 2.0 | 5 votes |
private static FusekiServer fusekiServerWithPatch(String dsName, int port, DatasetGraph dsgFuseki, String serviceName) { Operation patchOp = DeltaFuseki.patchOp; String patchContentType = "application/rdf-patch"; ActionService handler = new PatchApplyService(); FusekiServer server = FusekiServer.create() .registerOperation(patchOp, patchContentType, handler) .port(port) .add(dsName, dsgFuseki) .addOperation(dsName, DeltaFuseki.patchOp) .build(); return server ; }
Example #8
Source File: DeltaEx06_LocalDatasetToFuseki.java From rdf-delta with Apache License 2.0 | 5 votes |
public static void main2(String ...args) { // ---- Fuseki server with patch operation. int PORT = 2020 ; // In-memory dataset DatasetGraph dsgFuseki = DatasetGraphFactory.createTxnMem(); String serviceName = "patch"; FusekiServer server = fusekiServerWithPatch("/ds", PORT, dsgFuseki, serviceName); server.start(); // ---- Destination for changes is the Fuseki patch opration. String url = "http://localhost:"+PORT+"/ds/"+serviceName; RDFChanges changeSender = DeltaClientLib.destination(url); // In the case of http/https URLs, this is done with // RDFChanges changeSender = new RDFChangesHTTP(url); // ---- Local dataset. DatasetGraph dsgLocal = DatasetGraphFactory.createTxnMem(); // Combined datasetgraph and changes. // Changes will be POSTed to the URL. DatasetGraph dsg = RDFPatchOps.changes(dsgLocal, changeSender); // ---- Do something. Read in data.ttl inside a transaction. // (data.ttl is in src/main/resources/) Txn.executeWrite(dsg, ()->RDFDataMgr.read(dsg, "data.ttl") ); // ---- Query Fuseki RDFConnection conn = RDFConnectionFactory.connect("http://localhost:"+PORT+"/ds"); try( QueryExecution qExec = conn.query("PREFIX ex: <http://example.org/> SELECT * { ?s ?p ?o }") ) { ResultSet rs = qExec.execSelect(); ResultSetFormatter.out(rs, qExec.getQuery()); } }
Example #9
Source File: TestPatchFuseki.java From rdf-delta with Apache License 2.0 | 5 votes |
private Pair<FusekiServer, DatasetGraph> create() { int port = WebLib.choosePort(); DatasetGraph dsg = DatasetGraphFactory.createTxnMem(); String dsName = "/ds"; FusekiServer server = DeltaFuseki.fusekiWithPatch() .add(dsName, dsg) .addOperation(dsName, DeltaFuseki.patchOp) .build(); return Pair.create(server, dsg); }
Example #10
Source File: DeltaFuseki.java From rdf-delta with Apache License 2.0 | 5 votes |
/** * Build a Fuseki server whose dataset is a changes dataset wrapping the given base. */ public static FusekiServer deltaFuseki(int port, String name, DatasetGraph dsgBase, RDFChanges changes) { DatasetGraph dsg = RDFPatchOps.changes(dsgBase, changes); return FusekiServer.create().port(port) .add(name, dsg) .enablePing(true) .build(); }
Example #11
Source File: TestDeltaFusekiBad.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test public void patchserver_stop_start() { DeltaServer deltaServer = deltaServer(); FusekiServer server1 = fuseki1(); try { deltaServer.stop(); deltaServer = null; // Should fail try (RDFConnection conn0 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+ds1) ) { conn0.update(PREFIX+"INSERT DATA { :s :p 'update_patchserver_stop_start' }"); Assert.fail("Should not be able to update at the moment"); } catch (HttpException ex) { assertEquals(503, ex.getStatusCode()); // Expected - ignore. //assertTrue(ex.getResponseCode()>= 500); } deltaServer = deltaServer(Start.RESTART); try (RDFConnection conn1 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+ds1)) { conn1.query("ASK{}").execAsk(); } // Should be able to update. try (RDFConnection conn0 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+ds1) ) { conn0.update(PREFIX+"INSERT DATA { :s :p 'update_patchserver_stop_start' }"); } } finally { server1.stop(); if ( deltaServer != null ) deltaServer.stop(); } }
Example #12
Source File: TestDeltaFusekiBad.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test(expected=AssemblerException.class) public void fuseki_start() { // No DeltaServer running. //DeltaServer deltaServer = deltaServer(); // AssemblerException -> HttpException -> NoHttpResponseException // Assembler exception only if the dataset does not exis in the Zone. FusekiServer server1 = fuseki1(CLEAN); server1.stop(); }
Example #13
Source File: TestDeltaFusekiBad.java From rdf-delta with Apache License 2.0 | 5 votes |
@Test(expected=QueryExceptionHTTP.class) public void fuseki_stop() { DeltaServer deltaServer = deltaServer(CLEAN); FusekiServer server1 = fuseki1(CLEAN); try { server1.stop(); RDFConnection conn1 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+ds1) ; QueryExecution qExec = conn1.query("ASK{}"); qExec.execAsk(); } finally { deltaServer.stop(); } }
Example #14
Source File: BaseTestDeltaFuseki.java From rdf-delta with Apache License 2.0 | 5 votes |
private static FusekiServer fuseki(Start state, int port, String config, String zone) { switch (state) { case CLEAN : { Zone.clearZoneCache(); FileOps.clearDirectory(zone); break; } case RESTART : break; } return FusekiServer.create().port(port).loopback(true).parseConfigFile(config).build().start(); }
Example #15
Source File: Driver.java From rdf-delta with Apache License 2.0 | 5 votes |
protected static FusekiServer fuseki(int port, Model assembler) { Builder builder = FusekiServer.create() .loopback(true) .port(port); // Process server context Resource server = GraphUtils.getResourceByType(assembler, FusekiVocab.tServer); if ( server != null ) AssemblerUtils.mergeContext(server, Fuseki.getContext()) ; // Process services, whether via server ja:services or, if absent, by finding by type. List<DataAccessPoint> x = FusekiConfig.servicesAndDatasets(assembler); // Unbundle so that they accumulate. x.forEach(dap->builder.add(dap.getName(), dap.getDataService())); return builder.build(); }
Example #16
Source File: DeltaEx_FusekiHighAvailability.java From rdf-delta with Apache License 2.0 | 4 votes |
public static void main2(String ...args) { setup(); // Patch Log Server FileOps.exists(PLOG_DIR); FileOps.clearAll(PLOG_DIR); DeltaServer patchLogServer = DeltaServer.server(PLOG_PORT, PLOG_DIR); try { patchLogServer.start(); } catch (BindException ex) { System.err.println("Can't start the patch log server: "+ex.getMessage()); System.exit(1); } // For high availability, need a load balancer that switches between the two Fuskei servers. // Fuseki server 1 FusekiServer fuseki1 = fuseki1(); RDFConnection conn1 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+"/ds1") ; // Fuseki server 2 FusekiServer fuseki2 = fuseki2(); RDFConnection conn2 = RDFConnectionFactory.connect("http://localhost:"+F2_PORT+"/ds2") ; // Some data (data.ttl is in src/main/resources). Model model = RDFDataMgr.loadModel("data.ttl"); conn1.put(model); // Kill fuseki1. fuseki1.stop(); // And fetch data. Model model2 = conn2.fetch(); System.out.println(); RDFDataMgr.write(System.out, model2, Lang.NT); System.out.println(); // Remove a triple via conn2. conn2.update("PREFIX ex: <http://example.org/> DELETE DATA { ex:s ex:p ex:o }"); // Restart Fuseki1. fuseki1 = fuseki1(); // Not necesary. // conn1 = RDFConnectionFactory.connect("http://localhost:"+F1_PORT+"/ds1") ; Model model1 = conn1.fetch(); System.out.println(); // Data in Fuseki1. One less triple. RDFDataMgr.write(System.out, model1, Lang.NT); System.out.println(); }
Example #17
Source File: DeltaEx_FusekiHighAvailability.java From rdf-delta with Apache License 2.0 | 4 votes |
protected static FusekiServer fuseki1() { return fuseki(F1_PORT, FUSEKI_CONF_1); }
Example #18
Source File: DeltaEx_FusekiHighAvailability.java From rdf-delta with Apache License 2.0 | 4 votes |
protected static FusekiServer fuseki2() { return fuseki(F2_PORT, FUSEKI_CONF_2); }
Example #19
Source File: DeltaEx_FusekiHighAvailability.java From rdf-delta with Apache License 2.0 | 4 votes |
protected static FusekiServer fuseki(int port, String config) { return FusekiServer.create().port(port).parseConfigFile(config).build().start(); }
Example #20
Source File: DeltaFuseki.java From rdf-delta with Apache License 2.0 | 4 votes |
public static FusekiServer fuseki(int port, String config) { return FusekiServer.create().port(port).parseConfigFile(config).build().start(); }
Example #21
Source File: DeltaFuseki.java From rdf-delta with Apache License 2.0 | 4 votes |
/** Create a {@code FusekiServer.Builder} with registered patch operation. * To enable it, on a dataset "name", use {@code addOperation(name, "patch", DeltaFuseki.patchOp)}. * This makes it available by POST to {@code /name/patch} or {@code /name} with content-type "application/rdf-patch". */ public static FusekiServer.Builder fusekiWithPatch() { ActionService handler = new PatchApplyService(); return FusekiServer.create().registerOperation(patchOp, patchContentType, handler); }
Example #22
Source File: SPARQLQueryBuilderTest.java From inception with Apache License 2.0 | 4 votes |
@Before public void setUp() { ValueFactory vf = SimpleValueFactory.getInstance(); kb = new KnowledgeBase(); kb.setDefaultLanguage("en"); kb.setType(RepositoryType.LOCAL); kb.setFullTextSearchIri(null); kb.setMaxResults(1000); initRdfsMapping(); // Local RDF4J in-memory store - this should be used for most tests because we can // a) rely on its availability // b) import custom test data LuceneSail lucenesail = new LuceneSail(); lucenesail.setParameter(LuceneSail.LUCENE_RAMDIR_KEY, "true"); lucenesail.setBaseSail(new MemoryStore()); rdf4jLocalRepo = new SailRepository(lucenesail); rdf4jLocalRepo.init(); // Local Fuseki in-memory story fusekiServer = FusekiServer.create() .add("/fuseki", createFusekiFTSDataset()) .build(); fusekiServer.start() ; fusekiLocalRepo = new SPARQLRepository( "http://localhost:" + fusekiServer.getPort() + "/fuseki"); fusekiLocalRepo.init(); ukpVirtuosoRepo = new SPARQLRepository( "http://knowledgebase.ukp.informatik.tu-darmstadt.de:8890/sparql"); ukpVirtuosoRepo.init(); // http://zbw.eu/beta/sparql-lab/?endpoint=http://zbw.eu/beta/sparql/stw/query zbwStw = new SPARQLRepository("http://zbw.eu/beta/sparql/stw/query"); zbwStw.init(); // http://zbw.eu/beta/sparql-lab/?endpoint=http://zbw.eu/beta/sparql/gnd/query zbwGnd = new SPARQLRepository("http://zbw.eu/beta/sparql/gnd/query"); zbwGnd.init(); // https://query.wikidata.org/sparql wikidata = new SPARQLRepository("https://query.wikidata.org/sparql"); wikidata.init(); // https://dbpedia.org/sparql dbpedia = new SPARQLRepository("https://dbpedia.org/sparql"); dbpedia.init(); // https://linkeddata1.calcul.u-psud.fr/sparql yago = new SPARQLRepository("https://linkeddata1.calcul.u-psud.fr/sparql"); yago.init(); // http://nlp.dainst.org:8888/sparql hucit = new SPARQLRepository("http://nlp.dainst.org:8888/sparql"); hucit.init(); // http://collection.britishmuseum.org/sparql britishMuseum = new SPARQLRepository("http://collection.britishmuseum.org/sparql"); britishMuseum.init(); }
Example #23
Source File: BaseTestDeltaFuseki.java From rdf-delta with Apache License 2.0 | 4 votes |
protected static FusekiServer fuseki2(Start state) { return fuseki(state, F2_PORT, fuseki_conf2, "target/Zone2"); }
Example #24
Source File: BaseTestDeltaFuseki.java From rdf-delta with Apache License 2.0 | 4 votes |
protected static FusekiServer fuseki1(Start state) { return fuseki(state, F1_PORT, fuseki_conf1, "target/Zone1"); }
Example #25
Source File: BaseTestDeltaFuseki.java From rdf-delta with Apache License 2.0 | 4 votes |
protected static FusekiServer fuseki2() { return fuseki2(Start.CLEAN); }
Example #26
Source File: BaseTestDeltaFuseki.java From rdf-delta with Apache License 2.0 | 4 votes |
protected static FusekiServer fuseki1() { return fuseki1(Start.CLEAN); }
Example #27
Source File: Driver.java From rdf-delta with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws InterruptedException { // Fix up fuseki config files. // DELTA_PORT => value. // This is a template that needs updating, // Server 1. Model model = RDFDataMgr.loadModel("fuseki-config.ttl"); // fuseki:name "%DS_NAME%" // delta:changes "%LOG_URL%" // delta:patchlog "%LOG_NAME%" // delta:zone "%ZONE_NAME%" update(model, "%DS_NAME%", DS_NAME); String LOG_URL = "http://localhost:"+DELTA_PORT+"/"; update(model, "%LOG_URL%", LOG_URL); update(model, "%LOG_NAME%", PATCH_LOG_NAME); String zone1 = ZONE1.toString(); String zone2 = ZONE2.toString(); update(model, "%ZONE_NAME%", zone1); // --- Reset state. if ( true ) { FileOps.ensureDir(DELTA_DIR); FileOps.clearAll(DELTA_DIR); FileOps.ensureDir(zone1); FileOps.clearAll(zone1); FileOps.ensureDir(zone2); FileOps.clearAll(zone2); } DeltaServer logServer = deltaServer(DELTA_PORT, DELTA_DIR); try { logServer.start(); } catch (BindException e) { e.printStackTrace(); System.exit(0); } // RDFDataMgr.write(System.out, model, Lang.TTL); // System.out.flush(); FusekiServer server1 = fuseki(F1_PORT, model); server1.start(); //FusekiServer server2 = fuseki2(); int numClients = 10; int clientLoops = 10; CountDownLatch cdl1 = new CountDownLatch(numClients); CountDownLatch cdl2 = new CountDownLatch(numClients); for (int i = 0 ; i < numClients ; i++ ) { client(clientLoops, cdl1, cdl2); } cdl2.await(); logServer.stop(); System.out.println("DONE"); System.exit(0); }