use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.
the class ExFuseki_03_AddService_ContentType method main.
public static void main(String... args) {
// Create a new operation: operations are really just names (symbols). The code to
// run is found by looking up the operation in a per-server table that gives the server-specific
// implementation as an ActionService.
Operation myOperation = Operation.alloc("http://example/special3", "special3", "Custom operation");
// Service endpoint name.
String endpointName = "special";
String contentType = "application/special";
// The handled for the new operation.
ActionService customHandler = new DemoService();
FusekiServer server = FusekiServer.create().port(PORT).verbose(true).registerOperation(myOperation, contentType, customHandler).add(DATASET, DatasetGraphFactory.createTxnMem(), true).addEndpoint(DATASET, endpointName, myOperation).build();
// Start the server. This does not block this thread.
server.start();
// Try some operations on the server using the service URL.
String datasetURL = SERVER_URL + DATASET;
try {
// Dataset endpoint name : POST, with Content-type.
try (TypedInputStream stream = HttpOp.httpPostStream(datasetURL, contentType, BodyPublishers.ofString(""), "text/plain")) {
String s2 = FileUtils.readWholeFileAsUTF8(stream);
System.out.print(s2);
if (s2 == null)
System.out.println();
} catch (IOException ex) {
IO.exception(ex);
}
} finally {
server.stop();
}
}
use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.
the class ExFuseki_06_DataAccessCtl method main.
public static void main(String... a) {
FusekiLogging.setLogging();
int port = WebLib.choosePort();
String datasetName = "/ds";
String URL = format("http://localhost:%d%s", port, datasetName);
// ---- Set up the registry.
AuthorizationService authorizeSvc;
{
SecurityRegistry reg = new SecurityRegistry();
// user1 can see the default graph and :g1
reg.put("user1", new SecurityContextView("http://example/g1", Quad.defaultGraphIRI.getURI()));
// user2 can see :g1
reg.put("user2", new SecurityContextView("http://example/g1"));
// user3 can see :g1 and :g2
reg.put("user3", new SecurityContextView("http://example/g1", "http://example/g2"));
// Hide implementation.
authorizeSvc = reg;
}
// ---- Some data
DatasetGraph dsg = createData();
// ---- User authentication database (Jetty specific)
UserStore userStore = new UserStore();
addUserPassword(userStore, "user1", "pw1", "**");
addUserPassword(userStore, "user2", "pw2", "**");
try {
userStore.start();
} catch (Exception ex) {
throw new RuntimeException("UserStore", ex);
}
// ---- Build server, start server.
FusekiServer server = fuseki(port, userStore, authorizeSvc, datasetName, dsg);
server.start();
// ---- HttpClient connection with user and password basic authentication.
Authenticator authenticator = AuthLib.authenticator("user1", "pw1");
HttpClient client = HttpClient.newBuilder().authenticator(authenticator).connectTimeout(Duration.ofSeconds(10)).build();
// ---- Use it.
try (RDFConnection conn = RDFConnectionRemote.newBuilder().destination(URL).httpClient(client).build()) {
// What can we see of the database? user1 can see g1 and the default graph
System.out.println("\nFetch dataset");
Dataset ds1 = conn.fetchDataset();
RDFDataMgr.write(System.out, ds1, RDFFormat.TRIG_FLAT);
// Get a graph.
System.out.println("\nFetch named graph");
Model m1 = conn.fetch("http://example/g1");
RDFDataMgr.write(System.out, m1, RDFFormat.TURTLE_FLAT);
// Get a graph. user tries to get a graph they have no permission for ==> 404
System.out.println("\nFetch unexistent named graph");
try {
Model m2 = conn.fetch("http://example/g2");
} catch (HttpException ex) {
System.out.println(ex.getMessage());
}
}
// Need to exit the JVM : there is a background server
System.exit(0);
}
use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.
the class ExFuseki_09_Https_Auth method codeHttpsAuth.
public static FusekiServer codeHttpsAuth() {
FusekiLogging.setLogging();
// Some empty dataset
DatasetGraph dsg = DatasetGraphFactory.createTxnMem();
FusekiServer server = FusekiServer.create().verbose(true).https(3443, KEYSTORE, KEYSTOREPASSWORD).auth(AuthScheme.BASIC).passwordFile(PASSWD).add("/ds", dsg).build();
server.start();
// server.join();
return server;
}
use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.
the class TestRDFLinkFusekiBinary method rdflink_fuseki_1.
@Test
public void rdflink_fuseki_1() {
// Tests all run, in order, on one connection.
Triple triple = SSE.parseTriple("(:s :p <_:b3456>)");
Graph graph = GraphFactory.createDefaultGraph();
graph.add(triple);
FusekiServer server = createFusekiServer().build().start();
int port = server.getPort();
try {
String dsURL = "http://localhost:" + port + "/ds";
assertTrue(HttpLib.isFuseki(dsURL));
RDFLinkHTTPBuilder builder = RDFLinkFuseki.newBuilder().destination(dsURL);
try (RDFLinkFuseki link = (RDFLinkFuseki) builder.build()) {
// assertTrue(isFuseki(link));
// GSP
link.put(graph);
checkGraph(link, "b3456");
// Query forms.
link.querySelect("SELECT * {?s ?p ?o}", x -> {
Node obj = x.get(Var.alloc("o"));
assertTrue(obj.isBlank());
assertEquals("b3456", obj.getBlankNodeLabel());
});
try (QueryExec qExec = link.query("ASK {?s ?p <_:b3456>}")) {
boolean bool = qExec.ask();
assertTrue(bool);
}
try (QueryExec qExec = link.query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . FILTER (sameTerm(?o, <_:b3456>)) }")) {
Graph graph2 = qExec.construct();
checkGraph(graph2, "b3456");
}
try (QueryExec qExec = link.query("DESCRIBE ?s WHERE { ?s ?p <_:b3456>}")) {
Graph graph2 = qExec.describe();
checkGraph(graph2, "b3456");
}
// Update
link.update("CLEAR DEFAULT");
link.update("INSERT DATA { <x:s> <x:p> <_:b789> }");
checkGraph(link, "b789");
link.update("CLEAR DEFAULT");
link.update("INSERT DATA { <x:s> <x:p> <_:6789> }");
checkGraph(link, "6789");
}
} finally {
server.stop();
}
}
use of org.apache.jena.fuseki.main.FusekiServer in project jena by apache.
the class ExamplesServer method startServerWithAuth.
// Server with users and password.
public static FusekiServer startServerWithAuth(String dsName, DatasetGraph dsg, boolean verbose, String user, String password) {
Objects.requireNonNull(user);
Objects.requireNonNull(password);
UserStore userStore = JettyLib.makeUserStore(user, password);
SecurityHandler sh = JettyLib.makeSecurityHandler("Fuseki", userStore, AuthScheme.BASIC);
FusekiServer server = FusekiServer.create().port(0).loopback(true).verbose(verbose).enablePing(true).securityHandler(sh).serverAuthPolicy(Auth.policyAllowSpecific(user)).add(dsName, dsg).build();
server.start();
return server;
}
Aggregations