Search in sources :

Example 21 with FusekiServer

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

the class ExFusekiMain_1_Servlet_AddFilter method main.

public static void main(String... a) {
    try {
        FusekiLogging.setLogging();
        UserStore userStore = JettyLib.makeUserStore("u", "p");
        SecurityHandler sh = JettyLib.makeSecurityHandler("TripleStore", userStore, AuthScheme.BASIC);
        FusekiServer server = FusekiServer.create().add("/ds", DatasetGraphFactory.createTxnMem()).serverAuthPolicy(Auth.ANY_USER).securityHandler(sh).build();
        addExtraFilter(server);
        server.start();
        // And use it.
        String URL = "http://localhost:3330/ds";
        try (RDFConnection conn = RDFConnection.connectPW(URL, "u", "p")) {
            boolean b = conn.queryAsk("ASK{}");
            System.out.println("ASK=" + b);
        }
    // server.join();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        System.exit(0);
    }
}
Also used : SecurityHandler(org.eclipse.jetty.security.SecurityHandler) UserStore(org.eclipse.jetty.security.UserStore) RDFConnection(org.apache.jena.rdfconnection.RDFConnection) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) IOException(java.io.IOException)

Example 22 with FusekiServer

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

the class ExFuseki_02_Config_DataService method main.

public static void main(String... args) {
    // Register a new operation
    Operation myOperation = Operation.alloc("http://example/special2", "special2", "Custom operation");
    // Service endpoint names.
    String queryEndpoint = "q";
    String customEndpoint = "x";
    // Make a DataService with custom named for endpoints.
    // In this example, "q" for SPARQL query and "x" for our custom extension and no others.
    DatasetGraph dsg = DatasetGraphFactory.createTxnMem();
    DataService dataService = DataService.newBuilder(dsg).addEndpoint(myOperation, customEndpoint).addEndpoint(Operation.Query, queryEndpoint).build();
    // This will be the code to handled for the operation.
    ActionService customHandler = new DemoService();
    FusekiServer server = FusekiServer.create().port(PORT).verbose(true).registerOperation(myOperation, customHandler).add(DATASET, dataService).build();
    server.start();
    // Try some operations on the server using the service URL.
    String customOperationURL = SERVER_URL + DATASET + "/" + customEndpoint;
    String queryOperationURL = SERVER_URL + DATASET + "/" + queryEndpoint;
    Query query = QueryFactory.create("ASK{}");
    try {
        // Try custom name - OK
        try (QueryExecution qExec = QueryExecution.service(queryOperationURL, query)) {
            qExec.execAsk();
        }
        // Try the usual default name, which is not configured in the DataService so expect a 404.
        try (QueryExecution qExec = QueryExecution.service(SERVER_URL + DATASET + "/sparql", query)) {
            qExec.execAsk();
            throw new RuntimeException("Didn't fail");
        } catch (QueryExceptionHTTP ex) {
            if (ex.getStatusCode() != HttpSC.NOT_FOUND_404) {
                throw new RuntimeException("Not a 404", ex);
            }
        }
        // Make an HTTP GET to the custom operation.
        // Service endpoint name : GET
        String s1 = HttpOp.httpGetString(customOperationURL);
        if (s1 == null)
            throw new RuntimeException("Failed: " + customOperationURL);
    } finally {
        server.stop();
    }
}
Also used : Query(org.apache.jena.query.Query) Operation(org.apache.jena.fuseki.server.Operation) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) QueryExceptionHTTP(org.apache.jena.sparql.engine.http.QueryExceptionHTTP) ActionService(org.apache.jena.fuseki.servlets.ActionService) QueryExecution(org.apache.jena.query.QueryExecution) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) DataService(org.apache.jena.fuseki.server.DataService)

Example 23 with FusekiServer

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

the class ExFuseki_05_CustomFunction method main.

public static void main(String... a) {
    FusekiLogging.setLogging();
    // ---- Register the function
    FunctionRegistry ref = FunctionRegistry.get();
    ref.put("http://my/num", MyFunction.class);
    // ---- Show it can be used
    // -- Start a server
    int PORT = WebLib.choosePort();
    // Some empty dataset
    DatasetGraph dsg = DatasetGraphFactory.createTxnMem();
    FusekiServer server = FusekiServer.create().port(PORT).add("/ds", dsg).build();
    server.start();
    // -- Call the server
    String queryString = StrUtils.strjoinNL("SELECT * { ", "  VALUES ?Z { 123 'abc'}", "  BIND (<http://my/num>(?Z) AS ?X )", "}");
    try {
        String url = "http://localhost:" + PORT + "/ds";
        // Connect to the server and execute the query.
        try (RDFConnection conn = RDFConnection.connect(url)) {
            conn.queryResultSet(queryString, ResultSetFormatter::out);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        server.stop();
    }
}
Also used : FunctionRegistry(org.apache.jena.sparql.function.FunctionRegistry) ResultSetFormatter(org.apache.jena.query.ResultSetFormatter) RDFConnection(org.apache.jena.rdfconnection.RDFConnection) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 24 with FusekiServer

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

the class Shacl03_FusekiValidationService method main.

public static void main(String... a) throws IOException {
    FusekiLogging.setLogging();
    // If not standard registration...
    Operation op = Operation.alloc(FusekiVocab.NS + "shacl", "shacl", "SHACL valdiation");
    // FusekiExt.registerOperation(op, new SHACL_Validation());
    // FusekiExt.addDefaultEndpoint(op, "shacl");
    // Operation op = Operation.Shacl;
    FusekiServer server = FusekiServer.create().port(3030).add("/ds", DatasetGraphFactory.createTxnMem(), true).addEndpoint("/ds", "shacl", op).build();
    try {
        server.start();
        try (RDFConnection conn = RDFConnection.connect("http://localhost:3030/ds")) {
            conn.put("fu-data.ttl");
        }
        ValidationReport report = validateReport("http://localhost:3030/ds/shacl?graph=default", "fu-shapes.ttl");
        System.out.println();
        ShLib.printReport(report);
        System.out.println();
        System.out.println("- - - - - - - - - - - - - - - - - -");
        System.out.println();
        RDFDataMgr.write(System.out, report.getGraph(), Lang.TTL);
        System.out.println();
    } finally {
        server.stop();
    }
}
Also used : RDFConnection(org.apache.jena.rdfconnection.RDFConnection) ValidationReport(org.apache.jena.shacl.ValidationReport) Operation(org.apache.jena.fuseki.server.Operation) FusekiServer(org.apache.jena.fuseki.main.FusekiServer)

Example 25 with FusekiServer

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

the class ExamplesServer method startServer.

// Plain server
public static FusekiServer startServer(String dsName, DatasetGraph dsg, boolean verbose) {
    FusekiServer server = FusekiServer.create().port(0).loopback(true).verbose(verbose).enablePing(true).add(dsName, dsg).build();
    server.start();
    return server;
}
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