You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by "kinow (via GitHub)" <gi...@apache.org> on 2023/01/24 21:16:56 UTC

[GitHub] [jena] kinow commented on a diff in pull request #1729: Allow for overriding the default dispatch choice

kinow commented on code in PR #1729:
URL: https://github.com/apache/jena/pull/1729#discussion_r1085904835


##########
jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/Dispatcher.java:
##########
@@ -274,18 +316,23 @@ private static Endpoint chooseEndpoint(HttpAction action, DataService dataServic
         if ( ep != null )
             // Single dispatch, may not be valid.
             return ep;
+
         // No single direct dispatch. Multiple choices (different operation, same endpoint name)
-        // Work out which operation we are looking for.
-        Operation operation = chooseOperation(action);
-        ep = epSet.get(operation);
-        if ( ep == null ) {
-            if ( GSP_R.equals(operation) )
-                // If asking for GSP_R, and GSP_RW available, pass that back.
-                ep = epSet.get(GSP_RW);
-            else if ( GSP_RW.equals(operation) ) {
-                // If asking for GSP_RW, but only GSP_R available -> 405.
-                if ( epSet.contains(GSP_R) )
-                    ServletOps.errorMethodNotAllowed(action.getMethod());
+        // Work out which operation we are looking for based on SPARQL characteristics.
+        Operation operation = chooseOperation(action, epSet);
+
+     // Special case for GSP_R/GSP_RW

Review Comment:
   indentation



##########
jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/DispatchFunction.java:
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.server;
+
+import org.apache.jena.fuseki.servlets.HttpAction;
+
+/**
+ * Select a operation based on the request ({@link HttpAction}) and the choices at

Review Comment:
   s/a operation/an operation? And missing newline at the end of the file?



##########
jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/Dispatcher.java:
##########
@@ -395,27 +455,13 @@ private static void applyAuthentication(String user, DataService dataService, En
      * Assumes, and does not check, that the action is a GSP action.
      */
     private static Operation gspOperation(HttpAction action, HttpServletRequest request) {
-        // Check enabled.
-        if ( isReadMethod(request) )
-            return GSP_R;
-        else
-            return GSP_RW;
+        return isReadMethod(request) ? GSP_R : GSP_RW;
     }
 
     /**
-     * Determine the {@link Operation} for a Quads operation. (GSP, except on the
-     * whole dataset).
-     * <p>
-     * Assumes, and does not check, that the action is a Quads action.
+     * Return whether request method is a "read" (GET or HEAD) or "write", modifying
+     * (POST, PUT, DELETE, PATCH)

Review Comment:
   Out of curiosity, are the other methods (connect/trace/options) filtered by the web server, or further up/down the request chain?



##########
jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/Dispatcher.java:
##########
@@ -370,8 +419,19 @@ private static Operation chooseOperation(HttpAction action) {
         }
 
         // ---- No registered content type, no query parameters.
-        // Plain HTTP operation on the dataset handled as quads or rejected.
-        return quadsOperation(action, request);
+        // Plain HTTP operation on the dataset.
+        DispatchFunction selectOperation = action.getDataService().getDefaultOperationChooser();
+        if ( selectOperation == null )
+            // Defaul is a quads operation.

Review Comment:
   s/Defaul/Default



##########
jena-fuseki2/jena-fuseki-main/src/main/java/org/apache/jena/fuseki/main/sys/FusekiModules.java:
##########
@@ -38,35 +40,45 @@ public static void load() {
     }
 
     public static void reload() {
-        registry = ConcurrentHashMap.newKeySet();
+        registry = new ArrayList<>();
         subsystem = new Subsystem<FusekiModule>(FusekiModule.class);
         subsystem.initialize();
-        subsystem.forEach(registry::add);
+        synchronized(lock) {
+            subsystem.forEach(registry::add);
+        }
     }
 
     /** Add a code module */
     public static void add(FusekiModule module) {
-        load();
-        module.start();
-        registry.add(module);
+        synchronized(lock) {
+            load();
+            module.start();
+            registry.add(module);
+        }
     }
 
     /** Remove a code module */
     public static void remove(FusekiModule module) {
-        registry.remove(module);
-        module.stop();
+        synchronized(lock) {
+            registry.remove(module);
+            module.stop();
+        }
     }
 
     /** Test whether a code module is registered. */
     public static boolean contains(FusekiModule module) {
-        return registry.contains(module);
+        synchronized(lock) {
+            return registry.contains(module);
+        }
     }
 
     /*package*/ static void forEachModule(Consumer<FusekiModule> action) {
-        if ( registry == null )
-            load();
-        if ( registry == null || registry.isEmpty() )
-            return ;
-        registry.forEach(action);
+        synchronized(lock) {
+            if ( registry == null )
+                load();
+            if ( registry == null || registry.isEmpty() )

Review Comment:
   I think the `load()` call above means the `registry` cannot be null (it'll be at least an empty arraylist?)



##########
jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/Dispatcher.java:
##########
@@ -42,13 +42,55 @@
 /**
  * Dispatch on registered datasets. This is the entry point into Fuseki for dataset
  * operations.
- *
- * Administration operations, and directly registered servlets and static content are
- * called through the usual web server process.
- *
- * HTTP Request URLs, after servlet context removed, take the form {@code /dataset} or {@code /dataset/service}.
- * The most general URL is {@code /context/dataset/service}.
- * The {@link DataAccessPointRegistry} maps {@code /dataset} to a {@link DataAccessPoint}.
+ * <p>
+ * Administration operations, and directly registered servlets and static content,
+ * are called through the usual web server process.
+ * <p>
+ * HTTP Request URLs, after servlet context removed, take the form {@code /dataset}
+ * or {@code /dataset/service}. The most general URL is
+ * {@code /context/dataset/service}. The {@link DataAccessPointRegistry} maps
+ * {@code /dataset} to a {@link DataAccessPoint} which is a name and a
+ * {@linkplain DataService}.
+ * <p>
+ * The dispatch process is:
+ * </p>
+ * <p>
+ * 1. {@linkplain Dispatcher#dispatch} calls
+ * {@linkplain Dispatcher#locateDataAccessPoint} to get the
+ * {@linkplain DataAccessPoint} and calls {@linkplain Dispatcher#process}.
+ * </p>
+ * <p>
+ * 2. {@linkplain Dispatcher#process} create the {@linkplain HttpAction} then calls
+ * {@linkplain Dispatcher#dispatchAction} which calls through to
+ * {@linkplain Dispatcher#chooseProcessor}.
+ * </p>
+ * <p>
+ * 3. {@linkplain Dispatcher#chooseProcessor} does some checking and calls
+ * {@linkplain Dispatcher#chooseEndpoint}.
+ * </p>
+ * <p>
+ * 4. {@linkplain Dispatcher#chooseEndpoint} looks at request, and determines the
+ * {@linkplain EndpointSet}.
+ * </p>
+ * <p>
+ * 5. If there isn't an {@linkplain EndpointSet}, the dispatch process returns.
+ * </p>
+ * <p>
+ * 6. If there is exactly one entry, this is the outcome.
+ * </p>
+ * <p>
+ * 7. If there are multiple choices , {@linkplain Dispatcher#chooseOperation} looks
+ * at request and decides which {@linkplain Operation} is being requested based on
+ * SPARQL operations signatures and Content-Type.
+ * </p>
+ * <p>
+ * 8.There is a default for dispatches with multiple choices that can't be separated
+ * by SPARQL signature. These have no regsitered Content-type and no query string.
+ * </p>
+ * <p>
+ * A choice by dispatch does not necessarily mean an operation is valid and will be
+ * executed. It may fail authentication or not have an registered handler.

Review Comment:
   s/an registered/a registered



-- 
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.

To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org

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