use of org.apache.jena.fuseki.server.Operation 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.server.Operation in project jena by apache.
the class ExFuseki_04_CustomOperation_Inline method main.
public static void main(String... args) {
// Define the operation.
Operation operation = Operation.alloc("http://example/extra-service", "extra-service", "Test");
// Register globally.
FusekiExt.registerOperation(operation, new MyCustomService());
FusekiServer.create().port(3230).add("/ds", DatasetGraphFactory.createTxnMem()).addEndpoint("/ds", "extra", operation).build().start();
callOperation("extra");
System.exit(0);
}
use of org.apache.jena.fuseki.server.Operation in project jena by apache.
the class JsonDescription method describe.
public static void describe(JsonBuilder builder, DataAccessPoint access) {
builder.startObject();
builder.key(ServerConst.dsName).value(access.getName());
builder.key(ServerConst.dsState).value(access.getDataService().isAcceptingRequests());
builder.key(ServerConst.dsService);
builder.startArray();
for (Operation operation : access.getDataService().getOperations()) {
List<Endpoint> endpoints = access.getDataService().getEndpoints(operation);
describe(builder, operation, endpoints);
}
builder.finishArray();
builder.finishObject();
}
use of org.apache.jena.fuseki.server.Operation in project jena by apache.
the class BuildLib method loadOperationActionService.
/**
* Load a class (an {@link ActionService}) and create an {@link Operation} for it.
*/
/*package*/
static Pair<Operation, ActionService> loadOperationActionService(RDFNode implementation) {
String classURI = implementation.isLiteral() ? implementation.asLiteral().getLexicalForm() : ((Resource) implementation).getURI();
String javaScheme = "java:";
String fileScheme = "file:";
String scheme = null;
if (classURI.startsWith(javaScheme)) {
scheme = javaScheme;
} else if (classURI.startsWith(fileScheme)) {
scheme = fileScheme;
} else {
Fuseki.configLog.error("Class to load is not 'java:' or 'file:': " + classURI);
throw new FusekiConfigException("Not a 'java:' or 'file:' class reference: " + classURI);
}
String className = classURI.substring(scheme.length());
ActionService action = null;
try {
Class<?> cls;
if (Objects.equals(scheme, fileScheme)) {
try (URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { new URL(classURI) })) {
cls = Class.forName(className, true, urlClassLoader);
}
} else {
cls = Class.forName(className);
}
Constructor<?> x = cls.getConstructor();
action = (ActionService) x.newInstance();
} catch (ClassNotFoundException ex) {
throw new FusekiConfigException("Class not found: " + className);
} catch (Exception ex) {
throw new FusekiConfigException("Can't create object from " + className);
}
Operation op = Operation.alloc(NodeFactory.createBlankNode(), classURI, classURI);
return Pair.create(op, action);
}
use of org.apache.jena.fuseki.server.Operation in project jena by apache.
the class FusekiRequestsMetrics method bindTo.
@Override
public void bindTo(MeterRegistry registry) {
DataService dataService = dataAccessPoint.getDataService();
for (Operation operation : dataService.getOperations()) {
List<Endpoint> endpoints = dataService.getEndpoints(operation);
for (Endpoint endpoint : endpoints) {
CounterSet counters = endpoint.getCounters();
for (CounterName counterName : counters.counters()) {
Counter counter = counters.get(counterName);
Gauge.builder("fuseki_" + counterName.getFullName(), counter, Counter::value).tags(new String[] { "dataset", dataAccessPoint.getName(), "endpoint", endpoint.getName(), "operation", operation.getName(), "description", operation.getDescription() }).register(registry);
}
}
}
}
Aggregations