use of org.apache.jena.fuseki.server.Operation in project jena by apache.
the class ExFuseki_01_NamedService 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/special1", "special1", "Custom operation");
// Service endpoint name.
// This can be different for different datasets even in the same server.
// c.f. {@code fuseki:serviceQuery}
String endpointName = "special";
// The handled for the new operation.
ActionService customHandler = new DemoService();
FusekiServer server = FusekiServer.create().port(PORT).verbose(true).registerOperation(myOperation, 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 customOperationURL = SERVER_URL + DATASET + "/" + endpointName;
try {
// Service endpoint name : GET
String s1 = HttpOp.httpGetString(customOperationURL);
System.out.print(s1);
if (s1 == null)
System.out.println();
// Service endpoint name : POST
try (TypedInputStream stream = HttpOp.httpPostStream(customOperationURL, "text/plain")) {
String s2 = FileUtils.readWholeFileAsUTF8(stream);
System.out.print(s2);
if (s2 == null)
System.out.println();
} catch (IOException ex) {
IO.exception(ex);
}
// Service endpoint name. DELETE -> fails 405
try {
HttpOp.httpDelete(customOperationURL);
throw new IllegalStateException("DELETE succeeded");
} catch (HttpException ex) {
if (ex.getStatusCode() != HttpSC.METHOD_NOT_ALLOWED_405)
System.err.println("Unexpected HTTP Response Code: " + ex.getMessage());
else
System.out.println("DELETE rejected correctly: " + ex.getMessage());
}
} finally {
server.stop();
}
}
use of org.apache.jena.fuseki.server.Operation 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.server.Operation 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();
}
}
Aggregations