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();
}
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;
}
}
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;
}
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;
}
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);
}
}
Aggregations