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