Search in sources :

Example 1 with Operation

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();
    }
}
Also used : Operation(org.apache.jena.fuseki.server.Operation) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) IOException(java.io.IOException) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) ActionService(org.apache.jena.fuseki.servlets.ActionService)

Example 2 with Operation

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);
}
Also used : Operation(org.apache.jena.fuseki.server.Operation)

Example 3 with Operation

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();
}
Also used : Endpoint(org.apache.jena.fuseki.server.Endpoint) Operation(org.apache.jena.fuseki.server.Operation)

Example 4 with Operation

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);
}
Also used : FusekiConfigException(org.apache.jena.fuseki.FusekiConfigException) URLClassLoader(java.net.URLClassLoader) Operation(org.apache.jena.fuseki.server.Operation) ActionService(org.apache.jena.fuseki.servlets.ActionService) URL(java.net.URL) FusekiConfigException(org.apache.jena.fuseki.FusekiConfigException) JenaException(org.apache.jena.shared.JenaException)

Example 5 with Operation

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);
            }
        }
    }
}
Also used : Counter(org.apache.jena.fuseki.server.Counter) Endpoint(org.apache.jena.fuseki.server.Endpoint) CounterSet(org.apache.jena.fuseki.server.CounterSet) CounterName(org.apache.jena.fuseki.server.CounterName) Operation(org.apache.jena.fuseki.server.Operation) DataService(org.apache.jena.fuseki.server.DataService)

Aggregations

Operation (org.apache.jena.fuseki.server.Operation)8 FusekiServer (org.apache.jena.fuseki.main.FusekiServer)4 ActionService (org.apache.jena.fuseki.servlets.ActionService)4 IOException (java.io.IOException)2 TypedInputStream (org.apache.jena.atlas.web.TypedInputStream)2 DataService (org.apache.jena.fuseki.server.DataService)2 Endpoint (org.apache.jena.fuseki.server.Endpoint)2 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 HttpException (org.apache.jena.atlas.web.HttpException)1 FusekiConfigException (org.apache.jena.fuseki.FusekiConfigException)1 Counter (org.apache.jena.fuseki.server.Counter)1 CounterName (org.apache.jena.fuseki.server.CounterName)1 CounterSet (org.apache.jena.fuseki.server.CounterSet)1 Query (org.apache.jena.query.Query)1 QueryExecution (org.apache.jena.query.QueryExecution)1 RDFConnection (org.apache.jena.rdfconnection.RDFConnection)1 ValidationReport (org.apache.jena.shacl.ValidationReport)1 JenaException (org.apache.jena.shared.JenaException)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1