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

[GitHub] [jena] afs opened a new pull request, #1729: Allow for overriding the default dispatch choice

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

   GitHub issue resolved #1723
   
   Pull request Description:
   The PR allows a `DataService` to provide a custom handling of operations which are not recognized by the SPARQL protocols dispatcher.
   
   Some other Fuseki items found during development are included.
   
   ----
   
    - [x] Tests are included.
    - [x] Commits have been squashed to remove intermediate development commit messages.
    - [x] Key commit messages start with the issue number (GH-xxxx or JENA-xxxx)
   
   By submitting this pull request, I acknowledge that I am making a contribution to the Apache Software Foundation under the terms and conditions of the [Contributor's Agreement](https://www.apache.org/licenses/contributor-agreements.html).
   
   


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


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

Posted by "rvesse (via GitHub)" <gi...@apache.org>.
rvesse commented on code in PR #1729:
URL: https://github.com/apache/jena/pull/1729#discussion_r1086410954


##########
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:
   `OPTIONS` being rejected is most likely to be a problem for browser based UIs since it's used as a pre-flight request by browsers prior to sending the real request



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


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

Posted by "kinow (via GitHub)" <gi...@apache.org>.
kinow commented on code in PR #1729:
URL: https://github.com/apache/jena/pull/1729#discussion_r1086419309


##########
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:
   
   >Yes - but safe code in case load changes can leave the registry as null. Null tests are free! Its sort of left over from before synchonized. Multithreading startup complexity now avoided.
   
   :+1: sounds good to me, thanks!



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


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

Posted by "kinow (via GitHub)" <gi...@apache.org>.
kinow commented on code in PR #1729:
URL: https://github.com/apache/jena/pull/1729#discussion_r1086418186


##########
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:
   Yeah, I think for CORS some JS libraries did an `OPTIONS` request before. Not sure if/how that would work here, but worth considering that too.



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


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

Posted by "kinow (via GitHub)" <gi...@apache.org>.
kinow commented on code in PR #1729:
URL: https://github.com/apache/jena/pull/1729#discussion_r1086418186


##########
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:
   Yeah, I think for CORS some JS libraries did an `OPTIONS` request before. Not sure if/how that would work here, but worth considering that too.
   
   EDIT: TIL this actually has a name, [“CORS preflight request”](https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request).
   
   >A [CORS](https://developer.mozilla.org/en-US/docs/Glossary/CORS) preflight request is a CORS request that checks to see if the CORS protocol is understood and a server is aware using specific methods and headers.
   >
   >It is an [OPTIONS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS) request, using three HTTP request headers: [Access-Control-Request-Method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Request-Method), [Access-Control-Request-Headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Request-Headers), and the [Origin](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin) header.



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


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

Posted by "kinow (via GitHub)" <gi...@apache.org>.
kinow commented on code in PR #1729:
URL: https://github.com/apache/jena/pull/1729#discussion_r1086418186


##########
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:
   Yeah, I think for CORS some JS libraries did an `OPTIONS` request before. Not sure if/how that would work here, but worth considering that too.
   
   EDIT: this actually has a name, [“CORS preflight request”](https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request).
   
   >A [CORS](https://developer.mozilla.org/en-US/docs/Glossary/CORS) preflight request is a CORS request that checks to see if the CORS protocol is understood and a server is aware using specific methods and headers.
   >
   >It is an [OPTIONS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS) request, using three HTTP request headers: [Access-Control-Request-Method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Request-Method), [Access-Control-Request-Headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Request-Headers), and the [Origin](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin) header.



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


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

Posted by "kinow (via GitHub)" <gi...@apache.org>.
kinow commented on code in PR #1729:
URL: https://github.com/apache/jena/pull/1729#discussion_r1086418186


##########
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:
   Yeah, I think for CORS some JS libraries did an `OPTIONS` request before. Not sure if/how that would work here, but worth considering that too.
   
   EDIT: this actually has a name, [“CORS preflight request”](https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request).
   
   >A [CORS](https://developer.mozilla.org/en-US/docs/Glossary/CORS) preflight request is a CORS request that checks to see if the CORS protocol is understood and a server is aware using specific methods and headers.



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


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

Posted by "rvesse (via GitHub)" <gi...@apache.org>.
rvesse commented on code in PR #1729:
URL: https://github.com/apache/jena/pull/1729#discussion_r1086647181


##########
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:
   > @rvesse -- CORS pre-flight is handled before Fuseki.
   > 
   > https://github.com/apache/jena/blob/ea9406a6ca5be4e34c6e7db57e282947be529450/jena-fuseki2/jena-fuseki-main/src/main/java/org/apache/jena/fuseki/main/FusekiServer.java#L1452
   > 
   > It is only non-CORS OPTIONS here.
   
   I suspected as much, thanks for confirming



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


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

Posted by "afs (via GitHub)" <gi...@apache.org>.
afs commented on code in PR #1729:
URL: https://github.com/apache/jena/pull/1729#discussion_r1086361287


##########
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:
   PS
   
   Overloaded endpoint, GSP_RW: OPTIONS works.
   
   Overloaded endpoint, GSP_R: OPTIONS is rejected with "405 HTTP method not allowed: OPTIONS" which isn't illegal, just unhelpful.
   
   The dispatcher in just for SPARQL - it's a full HTTP REST environment! So I might fix it just because.
   



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


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

Posted by "afs (via GitHub)" <gi...@apache.org>.
afs commented on code in PR #1729:
URL: https://github.com/apache/jena/pull/1729#discussion_r1086336786


##########
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:
   `ActionProcessor` has a switch on method type. TRACE isn't provided by any service IIRC. https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/TRACE questions whether it is used in browsers at all.
   
   CONNECT doesn't get to the dispatcher.
   (I'll add a definite rejection case to `ActionProcessor` to reject it rather than ignore it.)
   
   It looks like OPTIONS works properly for everything except for multifunction endpoints for quads operations (this one case in `Dispatcher`).
   
   We can't tell if it is "read" or "write" until the real operation is tried.
   
   GSP_R vs GSP_RW is a weird case - one is a subset of the other.
   
   So it gets "GSP_RW" which gives the full range of methods possible. Unfortunately, if only GSP_R is configured it will bounced because there is no implementation of GSP_RW.  Probably a corner case bug.
   
   Having secure by-design read-only operation is more important than details of OPTIONS (which I never seen used on Fuseki - except by the test suite).
   



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


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

Posted by "kinow (via GitHub)" <gi...@apache.org>.
kinow commented on code in PR #1729:
URL: https://github.com/apache/jena/pull/1729#discussion_r1086418682


##########
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:
   Thanks for the explanation & investigation @afs!



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


[GitHub] [jena] afs merged pull request #1729: GH-1723: Allow for overriding the default dispatch choice

Posted by "afs (via GitHub)" <gi...@apache.org>.
afs merged PR #1729:
URL: https://github.com/apache/jena/pull/1729


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


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

Posted by "kinow (via GitHub)" <gi...@apache.org>.
kinow commented on code in PR #1729:
URL: https://github.com/apache/jena/pull/1729#discussion_r1087043906


##########
jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/Dispatcher.java:
##########
@@ -463,6 +509,8 @@ private static Operation gspOperation(HttpAction action, HttpServletRequest requ
      * (POST, PUT, DELETE, PATCH)
      */
     private static boolean isReadMethod(HttpServletRequest request) {
+        // OPTIONS needs to knwo if the EndPoitn set contains GSP_R or GSP_RW.

Review Comment:
   s/knwo/know and s/EndPoitn/Endpoint or EndPoint



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


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

Posted by "afs (via GitHub)" <gi...@apache.org>.
afs commented on code in PR #1729:
URL: https://github.com/apache/jena/pull/1729#discussion_r1087134322


##########
jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/Dispatcher.java:
##########
@@ -463,6 +509,8 @@ private static Operation gspOperation(HttpAction action, HttpServletRequest requ
      * (POST, PUT, DELETE, PATCH)
      */
     private static boolean isReadMethod(HttpServletRequest request) {
+        // OPTIONS needs to knwo if the EndPoitn set contains GSP_R or GSP_RW.

Review Comment:
   Removed comment (it's not right anymore).



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


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

Posted by "kinow (via GitHub)" <gi...@apache.org>.
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


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

Posted by "afs (via GitHub)" <gi...@apache.org>.
afs commented on code in PR #1729:
URL: https://github.com/apache/jena/pull/1729#discussion_r1086336786


##########
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:
   `ActionProcessor` has a switch on method type. TRACE isn't provided by any service IIRC. https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/TRACE questions whether it is used in browsers at all.
   
   CONNECT doesn't get to the dispatcher.
   (I'll add a definite rejection case to `ActionProcessor` to reject it rather than ignore it.)
   
   It looks like OPTIONS works properly for everything except for multifunction endpoints for quads operations (this one case in `Dispatcher`).
   
   We can't tell if it is "read" or "write" until the real operation is tried.
   
   GSP_R vs GSP_RW is a weird case - one is a subset of the other. See the special code at the end of `Dispatcher.chooseEndpoint`. (It happens in both single and overloaded dispatch. I put it there to keep the decision code clearer - I didn't think of the OPTIONS case.)
   
   So it gets "GSP_RW" which gives the full range of methods possible. Unfortunately, if only GSP_R is configured it will bounced because there is no implementation of GSP_RW.  Probably a corner case bug.
   
   Having secure by-design read-only operation is more important than details of OPTIONS (which I never seen used on Fuseki - except by the test suite).
   



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


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

Posted by "afs (via GitHub)" <gi...@apache.org>.
afs commented on code in PR #1729:
URL: https://github.com/apache/jena/pull/1729#discussion_r1086339729


##########
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:
   Yes - but safe code in case `load` changes can leave the registry as null. Null tests are free! Its sort of left over from before `synchonized`. Multithreading startup complexity now avoided.



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


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

Posted by "afs (via GitHub)" <gi...@apache.org>.
afs commented on code in PR #1729:
URL: https://github.com/apache/jena/pull/1729#discussion_r1086437690


##########
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:
   @rvesse -- CORS pre-flight is handled before Fuseki.
   
   https://github.com/apache/jena/blob/ea9406a6ca5be4e34c6e7db57e282947be529450/jena-fuseki2/jena-fuseki-main/src/main/java/org/apache/jena/fuseki/main/FusekiServer.java#L1452
   
   It is only non-CORS OPTIONS here.



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