Search in sources :

Example 11 with FusekiServer

use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.

the class TestRDFConnectionFusekiBinary method rdfconnection_fuseki_1.

@Test
public void rdfconnection_fuseki_1() {
    // Tests all run, in order, on one connection.
    Triple triple = SSE.parseTriple("(:s :p <_:b3456>)");
    // Goes in as URI! (pre this PR)
    Model model = ModelFactory.createDefaultModel();
    model.getGraph().add(triple);
    int PORT = WebLib.choosePort();
    FusekiServer server = createFusekiServer(PORT).build().start();
    try {
        String dsURL = "http://localhost:" + PORT + "/ds";
        assertTrue(HttpLib.isFuseki(dsURL));
        RDFConnectionRemoteBuilder builder = RDFConnectionFuseki.create().destination(dsURL);
        try (RDFConnectionFuseki conn = (RDFConnectionFuseki) builder.build()) {
            assertTrue(HttpLib.isFuseki(dsURL));
            // GSP
            conn.put(model);
            checkModel(conn, "b3456");
            // Query forms.
            conn.querySelect("SELECT * {?s ?p ?o}", x -> {
                Node obj = x.get("o").asNode();
                assertTrue(obj.isBlank());
                assertEquals("b3456", obj.getBlankNodeLabel());
            });
            try (QueryExecution qExec = conn.query("ASK {?s ?p <_:b3456>}")) {
                boolean bool = qExec.execAsk();
                assertTrue(bool);
            }
            try (QueryExecution qExec = conn.query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . FILTER (sameTerm(?o, <_:b3456>)) }")) {
                Model model2 = qExec.execConstruct();
                checkModel(model2, "b3456");
            }
            try (QueryExecution qExec = conn.query("DESCRIBE ?s WHERE { ?s ?p <_:b3456>}")) {
                Model model2 = qExec.execConstruct();
                checkModel(model2, "b3456");
            }
            // Update
            conn.update("CLEAR DEFAULT");
            conn.update("INSERT DATA { <x:s> <x:p> <_:b789> }");
            checkModel(conn, "b789");
            conn.update("CLEAR DEFAULT");
            conn.update("INSERT DATA { <x:s> <x:p> <_:6789> }");
            checkModel(conn, "6789");
        }
    } finally {
        server.stop();
    }
}
Also used : Triple(org.apache.jena.graph.Triple) RDFConnectionRemoteBuilder(org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder) Node(org.apache.jena.graph.Node) Model(org.apache.jena.rdf.model.Model) RDFConnectionFuseki(org.apache.jena.rdfconnection.RDFConnectionFuseki) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) QueryExecution(org.apache.jena.query.QueryExecution) Test(org.junit.Test)

Example 12 with FusekiServer

use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.

the class TestFusekiRDFS method fuseki_rdfs_1.

// Test building a Fuseki server with an RDFS dataset.
@Test
public void fuseki_rdfs_1() {
    Graph schema = SSE.parseGraph("(graph (:p rdfs:range :T))");
    DatasetGraph dsg0 = DatasetGraphFactory.createTxnMem();
    DatasetGraph dsg = RDFSFactory.datasetRDFS(dsg0, schema);
    dsg.add(SSE.parseQuad("(_ :s :p :o)"));
    FusekiServer server = FusekiServer.create().port(0).add("/ds", dsg).build();
    server.start();
    int port = server.getHttpPort();
    String URL = "http://localhost:" + port + "/ds";
    try (RDFConnection conn = RDFConnection.connect(URL)) {
        conn.queryResultSet("PREFIX :<http://example/> SELECT ?t { :o a ?t }", rs -> {
            assertTrue(rs.hasNext());
            String type = rs.next().getResource("t").getURI();
            assertFalse(rs.hasNext());
            assertEquals(type, "http://example/T");
        });
    }
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) RDFConnection(org.apache.jena.rdfconnection.RDFConnection) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 13 with FusekiServer

use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.

the class TestGeoAssembler method test.

private void test(String filename, String dbName) {
    FusekiServer server = FusekiServer.create().port(0).parseConfigFile("file:" + DIR + filename).build();
    try {
        server.start();
        int port = server.getPort();
        String URL = "http://localhost:" + port + "/" + dbName;
        String queryStr = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "\n" + "SELECT *\n" + "WHERE{\n" + // "{ <http://example.org/Geometry#PolygonH> ?P ?O } UNION \n"
        " {  <http://example.org/Geometry#PolygonH> geo:sfContains ?obj }\n" + // + "    <http://example.org/Geometry#PolygonH> ?P ?obj .\n"
        "} ORDER by ?obj";
        RowSet rs = QueryExec.service(URL).query(queryStr).select();
        long x = RowSetOps.count(rs);
        assertEquals(8, x);
    } finally {
        server.stop();
    }
}
Also used : RowSet(org.apache.jena.sparql.exec.RowSet) FusekiServer(org.apache.jena.fuseki.main.FusekiServer)

Example 14 with FusekiServer

use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.

the class EnvTest method startServer.

private static FusekiServer startServer(String dsName, DatasetGraph dsg, StringHolderServlet holder, boolean verbose, String user, String password) {
    if (user != null && password == null)
        throw new IllegalArgumentException("User, not null, but  password null");
    if (user != null) {
    }
    String data = "/data";
    FusekiServer.Builder builder = FusekiServer.create().port(0).verbose(verbose).enablePing(true).auth(AuthScheme.BASIC).addServlet(data, holder).add(dsName, dsg);
    if (user != null) {
        UserStore userStore = JettyLib.makeUserStore(user, password);
        SecurityHandler sh = JettyLib.makeSecurityHandler("TripleStore", userStore, AuthScheme.BASIC);
        builder.securityHandler(sh).serverAuthPolicy(Auth.policyAllowSpecific(user));
    }
    FusekiServer server = builder.build();
    server.start();
    return server;
}
Also used : SecurityHandler(org.eclipse.jetty.security.SecurityHandler) UserStore(org.eclipse.jetty.security.UserStore) FusekiServer(org.apache.jena.fuseki.main.FusekiServer)

Example 15 with FusekiServer

use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.

the class ExModelStore01 method main.

public static void main(String... args) {
    try {
        // Setup a server.
        FusekiLogging.setLogging();
        FusekiServer server = ExamplesServer.startServer(dsName, dsg, false);
        String dataURL = "http://localhost:" + server.getPort() + "/" + dsName;
        RDFParser.fromString(rdfString).lang(Lang.TTL).parse(someData);
        exampleModelStore(dataURL);
    } catch (Throwable th) {
        th.printStackTrace();
    } finally {
        // The server is in the background so explicitly exit the process
        System.exit(0);
    }
}
Also used : FusekiServer(org.apache.jena.fuseki.main.FusekiServer)

Aggregations

FusekiServer (org.apache.jena.fuseki.main.FusekiServer)25 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)10 RDFConnection (org.apache.jena.rdfconnection.RDFConnection)6 Operation (org.apache.jena.fuseki.server.Operation)4 UserStore (org.eclipse.jetty.security.UserStore)4 IOException (java.io.IOException)3 ActionService (org.apache.jena.fuseki.servlets.ActionService)3 SecurityHandler (org.eclipse.jetty.security.SecurityHandler)3 Test (org.junit.Test)3 HttpException (org.apache.jena.atlas.web.HttpException)2 TypedInputStream (org.apache.jena.atlas.web.TypedInputStream)2 DataService (org.apache.jena.fuseki.server.DataService)2 Graph (org.apache.jena.graph.Graph)2 Node (org.apache.jena.graph.Node)2 Triple (org.apache.jena.graph.Triple)2 QueryExecution (org.apache.jena.query.QueryExecution)2 Model (org.apache.jena.rdf.model.Model)2 Authenticator (java.net.Authenticator)1 BindException (java.net.BindException)1 HttpClient (java.net.http.HttpClient)1