You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by GitBox <gi...@apache.org> on 2020/10/09 15:26:48 UTC

[GitHub] [jena] afs opened a new pull request #808: JENA-1978: Fuseki examples

afs opened a new pull request #808:
URL: https://github.com/apache/jena/pull/808


   Includes JENA-1976 (dft CORS to on)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] afs merged pull request #808: JENA-1978: Fuseki examples

Posted by GitBox <gi...@apache.org>.
afs merged pull request #808:
URL: https://github.com/apache/jena/pull/808


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] kinow commented on a change in pull request #808: JENA-1978: Fuseki examples

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #808:
URL: https://github.com/apache/jena/pull/808#discussion_r502737676



##########
File path: jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/examples/ExFuseki_4_CustomOperation_External.java
##########
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.fuseki.main.examples;
+
+import java.util.ServiceLoader;
+
+import org.apache.jena.fuseki.main.FusekiServer;
+import org.apache.jena.fuseki.system.FusekiLogging;
+import org.apache.jena.riot.web.HttpOp;
+import org.apache.jena.sparql.core.DatasetGraphFactory;
+import org.apache.jena.sys.JenaSystem;
+
+/**
+ * Example of adding a new operation to a Fuseki server by registering it with the
+ * global Fuseki registries.
+ *
+ * The custom operation is loaded using {@link ServiceLoader} as shown in
+ * {@link InitFusekiCustomOperation}.
+ *
+ * Doing this, adding the jar to the classpath, including the {@link ServiceLoader}
+ * setup, will automatically add it to the server.
+ * <p>
+ * See <a href="https://jena.apache.org/documentation/notes/jena-repack.html">Repacking Jena jars</a>.
+ * <p>
+ * See <a href="https://jena.apache.org/documentation/notes/system-initialization.html">System Initialization</a>
+ */
+public class ExFuseki_4_CustomOperation_External {
+
+    static {
+        JenaSystem.init();
+        FusekiLogging.setLogging();
+    }
+
+    // Example usage.
+    public static void main(String...args) {
+
+        // Imitate Service loader behaviour.
+        new InitFusekiCustomOperation().start();
+
+
+        // Standard Fuseki startup by commandline.
+        // /ds/extra will be added because InitFusekiCustomOperation adds it to the default services.
+
+        // ThreadLib.async(()->FusekiMainCmd.main("--port=3230", "--mem", "/ds"));
+        //Lib.sleep(1000);
+        // Same as the above command line except it does not block the thread (which is why the ThreadLib.async is added).
+        FusekiServer.create().port(3230).add("/ds", DatasetGraphFactory.createTxnMem()).build().start();
+
+        callOperation("extra");
+        System.exit(0);
+    }
+
+    private static void callOperation(String name) {
+        String x = HttpOp.execHttpGetString("http://localhost:3230/ds/"+name);
+        if ( x == null ) {
+            System.out.println("Not found : <null>");
+        } else {
+            System.out.print(x);
+            if ( ! x.endsWith("\n") )
+                System.out.println();
+        }
+    }
+}

Review comment:
       Missing newline

##########
File path: jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/examples/InitFusekiCustomOperation.java
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.fuseki.main.examples;
+
+import java.io.IOException;
+
+import org.apache.jena.atlas.lib.DateTimeUtils;
+import org.apache.jena.fuseki.Fuseki;
+import org.apache.jena.fuseki.FusekiException;
+import org.apache.jena.fuseki.build.FusekiExt;
+import org.apache.jena.fuseki.server.Operation;
+import org.apache.jena.fuseki.servlets.ActionService;
+import org.apache.jena.fuseki.servlets.HttpAction;
+import org.apache.jena.riot.WebContent;
+import org.apache.jena.sys.JenaSubsystemLifecycle;
+import org.apache.jena.web.HttpSC;
+
+/**
+* See https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html
+*
+* Example: the file has one line which is the full package, class name.
+* Build: src/main/resources/META-INF/services/org.apache.jena.sys.JenaSubsystemLifecycle
+* ----
+* fuseki.examples.Ex_FusekiCustomOperation.InitFusekiCustomOperation
+* ----
+*/
+public class InitFusekiCustomOperation implements JenaSubsystemLifecycle {
+
+    public InitFusekiCustomOperation() {}
+
+    @Override
+    public void start() {
+        // Can use Fuseki server logging.
+        Fuseki.configLog.info("Add custom operation");
+        System.err.println("**** Fuseki extension ****");
+        Operation op = Operation.alloc("http://example/extra-service", "extra-service", "Test");
+        FusekiExt.registerOperation(op, new MyCustomService());
+        FusekiExt.addDefaultEndpoint(op, "extra");
+    }
+
+    @Override
+    public void stop() {}
+
+    @Override
+    public int level() { return 1000; }
+
+    // For convenience of the example - include the implementation of the custom operation in the same file.
+    private static class MyCustomService extends ActionService {
+
+        // Choose.
+        @Override
+        public void execGet(HttpAction action) {
+            executeLifecycle(action);
+        }
+
+        @Override
+        public void validate(HttpAction action) { }
+
+        @Override
+        public void execute(HttpAction action) {
+            action.response.setStatus(HttpSC.OK_200);
+            action.response.setContentType(WebContent.contentTypeTextPlain);
+            try {
+                action.response.getOutputStream().print("** GET ** "+DateTimeUtils.nowAsXSDDateTimeString());
+            } catch (IOException e) {
+                throw new FusekiException(e);
+            }
+        }
+    }
+}

Review comment:
       Missing newline




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org


[GitHub] [jena] kinow commented on a change in pull request #808: JENA-1978: Fuseki examples

Posted by GitBox <gi...@apache.org>.
kinow commented on a change in pull request #808:
URL: https://github.com/apache/jena/pull/808#discussion_r502661977



##########
File path: jena-fuseki2/jena-fuseki-main/src/main/java/org/apache/jena/fuseki/main/cmds/FusekiMain.java
##########
@@ -82,8 +82,9 @@
     private static ArgDecl  argConfig       = new ArgDecl(ArgDecl.HasValue, "config", "conf");
     private static ArgDecl  argGZip         = new ArgDecl(ArgDecl.HasValue, "gzip");
     private static ArgDecl  argBase         = new ArgDecl(ArgDecl.HasValue, "base", "files");
-
+    

Review comment:
       Extra spaces




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org