Search in sources :

Example 6 with FusekiServer

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

the class ExFusekiMain_3_FusekiModule method main.

public static void main(String... a) throws Exception {
    JenaSystem.init();
    FusekiLogging.setLogging();
    // Normally done with ServiceLoader
    // A file /META-INF/services/org.apache.jena.fuseki.main.sys.FusekiModule
    // in the jar file with contents:
    // org.apache.jena.fuseki.main.examples.ExampleModule
    // 
    // The file is typically put into the jar by having
    // src/main/resources/META-INF/services/org.apache.jena.fuseki.main.sys.FusekiModule
    FusekiModule module = new FMod_ProvidePATCH();
    FusekiModules.add(module);
    // Create server.
    FusekiServer server = FusekiServer.create().port(0).build().start();
    int port = server.getPort();
    // Client HTTP request: "PATCH /extra"
    HttpRequest request = HttpRequest.newBuilder().uri(URI.create("http://localhost:" + port + "/extra")).method("PATCH", BodyPublishers.ofString("hello world!")).build();
    HttpResponse<Void> response = HttpEnv.getDftHttpClient().send(request, BodyHandlers.discarding());
    server.stop();
}
Also used : HttpRequest(java.net.http.HttpRequest) FusekiModule(org.apache.jena.fuseki.main.sys.FusekiModule) FusekiServer(org.apache.jena.fuseki.main.FusekiServer)

Example 7 with FusekiServer

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

the class TestSecurityConfig method test.

private static void test(String configFile, Consumer<FusekiServer> action) {
    FusekiServer fusekiServer = fusekiServer(configFile);
    try {
        action.accept(fusekiServer);
    } finally {
        fusekiServer.stop();
        fusekiServer = null;
    }
}
Also used : FusekiServer(org.apache.jena.fuseki.main.FusekiServer)

Example 8 with FusekiServer

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

the class TestSecurityConfig method fusekiServer.

private static FusekiServer fusekiServer(String configFile) {
    FusekiServer fusekiServer = FusekiServer.create().port(0).parseConfigFile(configFile).passwordFile("testing/Access/passwd").build();
    fusekiServer.start();
    return fusekiServer;
}
Also used : FusekiServer(org.apache.jena.fuseki.main.FusekiServer)

Example 9 with FusekiServer

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

the class AbstractTestFusekiSecurityAssembler method setup.

private static FusekiServer setup(String assembler, boolean sharedDatabase) {
    // This will have a warning because authentication is not set (no password
    // file, no security handler) and that's what we want - no authentication -
    // because we use "user.get()"in the tests.
    // 
    // Altering the logging level is simply to avoid the Fuseki.configLog message
    // in "build()" without turning warnings off everywhere.
    // -- Start log manipulation.
    String level = LogCtl.getLevel(Fuseki.configLog.getName());
    LogCtl.disable(Fuseki.configLog);
    // In case Fuseki.configLog is active - make sure the test log shows the build()
    // message is expected.
    Fuseki.configLog.warn("  (Expect one warning here)");
    FusekiServer server = FusekiServer.create().port(0).parseConfigFile(assembler).build();
    // Special way to get the servlet remote user (the authorized principle).
    FusekiLib.modifyForAccessCtl(server.getDataAccessPointRegistry(), (a) -> user.get());
    server.start();
    LogCtl.setLevel(Fuseki.configLog, level);
    if (sharedDatabase) {
        String data = StrUtils.strjoinNL("PREFIX : <http://example/>", "INSERT DATA {", "   :s0 :p :o .", "   GRAPH <http://host/graphname1> {:s1 :p :o}", "   GRAPH <http://host/graphname3> {:s3 :p :o}", "   GRAPH <http://host/graphname9> {:s9 :p :o}", "}");
        String plainUrl = server.datasetURL("/plain");
        try (RDFConnection conn = RDFConnection.connect(plainUrl)) {
            conn.update(data);
        }
    } else {
        DatasetGraph dsg = server.getDataAccessPointRegistry().get("/database").getDataService().getDataset();
        Txn.executeWrite(dsg, () -> {
            dsg.add(SSE.parseQuad("(<http://host/graphname1> :s1 :p :o)"));
            dsg.add(SSE.parseQuad("(<http://host/graphname3> :s3 :p :o)"));
            dsg.add(SSE.parseQuad("(<http://host/graphname9> :s9 :p :o)"));
        });
    }
    return server;
}
Also used : RDFConnection(org.apache.jena.rdfconnection.RDFConnection) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 10 with FusekiServer

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

the class FusekiMain method exec.

@Override
protected void exec() {
    try {
        FusekiServer server = buildServer(serverConfig);
        info(server);
        try {
            server.start();
        } catch (FusekiException ex) {
            if (ex.getCause() instanceof BindException) {
                if (serverConfig.jettyConfigFile == null)
                    Fuseki.serverLog.error("Failed to start server: " + ex.getCause().getMessage() + ": port=" + serverConfig.port);
                else
                    Fuseki.serverLog.error("Failed to start server: " + ex.getCause().getMessage() + ": port in use");
                System.exit(1);
            }
            throw ex;
        } catch (Exception ex) {
            throw new FusekiException("Failed to start server: " + ex.getMessage(), ex);
        }
        server.join();
        System.exit(0);
    } catch (AssemblerException | FusekiException ex) {
        if (ex.getCause() != null)
            System.err.println(ex.getCause().getMessage());
        else
            System.err.println(ex.getMessage());
        throw new TerminationException(1);
    }
}
Also used : TerminationException(org.apache.jena.cmd.TerminationException) AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) FusekiException(org.apache.jena.fuseki.FusekiException) BindException(java.net.BindException) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) RiotException(org.apache.jena.riot.RiotException) BindException(java.net.BindException) AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) FusekiException(org.apache.jena.fuseki.FusekiException) CmdException(org.apache.jena.cmd.CmdException) TerminationException(org.apache.jena.cmd.TerminationException)

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