You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2024/04/09 16:59:23 UTC
(jena) 02/06: GH-2392: Fuseki/webapp: settable context path
This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
commit 2f3a2930b9e673ca0f1f9495ce0e7f89b04ff5ea
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Fri Apr 5 21:16:27 2024 +0100
GH-2392: Fuseki/webapp: settable context path
---
.../apache/jena/fuseki/main/cmds/FusekiMain.java | 2 +-
.../java/org/apache/jena/fuseki/cmd/FusekiCmd.java | 17 +++---
.../apache/jena/fuseki/cmd/JettyFusekiWebapp.java | 68 ++++++++--------------
3 files changed, 33 insertions(+), 54 deletions(-)
diff --git a/jena-fuseki2/jena-fuseki-main/src/main/java/org/apache/jena/fuseki/main/cmds/FusekiMain.java b/jena-fuseki2/jena-fuseki-main/src/main/java/org/apache/jena/fuseki/main/cmds/FusekiMain.java
index 3010eb7b16..fbbda7ab6b 100644
--- a/jena-fuseki2/jena-fuseki-main/src/main/java/org/apache/jena/fuseki/main/cmds/FusekiMain.java
+++ b/jena-fuseki2/jena-fuseki-main/src/main/java/org/apache/jena/fuseki/main/cmds/FusekiMain.java
@@ -98,7 +98,7 @@ public class FusekiMain extends CmdARQ {
// Static files. URLs are affected by argPathBase
private static ArgDecl argBase = new ArgDecl(ArgDecl.HasValue, "base", "files");
- private static ArgDecl argCORS = new ArgDecl(ArgDecl.HasValue, "withCORS", "cors", "CORS", "cors-config");
+ private static ArgDecl argCORS = new ArgDecl(ArgDecl.HasValue, "withCORS", "cors", "CORS", "cors-config");
private static ArgDecl argNoCORS = new ArgDecl(ArgDecl.NoValue, "noCORS", "no-cors");
private static ArgDecl argWithPing = new ArgDecl(ArgDecl.NoValue, "withPing", "ping");
private static ArgDecl argWithStats = new ArgDecl(ArgDecl.NoValue, "withStats", "stats");
diff --git a/jena-fuseki2/jena-fuseki-webapp/src/main/java/org/apache/jena/fuseki/cmd/FusekiCmd.java b/jena-fuseki2/jena-fuseki-webapp/src/main/java/org/apache/jena/fuseki/cmd/FusekiCmd.java
index a0599b07cc..d80d5b6fc9 100644
--- a/jena-fuseki2/jena-fuseki-webapp/src/main/java/org/apache/jena/fuseki/cmd/FusekiCmd.java
+++ b/jena-fuseki2/jena-fuseki-webapp/src/main/java/org/apache/jena/fuseki/cmd/FusekiCmd.java
@@ -76,7 +76,6 @@ public class FusekiCmd {
private static ArgDecl argMemTDB = new ArgDecl(ArgDecl.NoValue, "memtdb", "memTDB", "tdbmem");
// And not ModLocation.
private static ArgDecl argTDB = new ArgDecl(ArgDecl.HasValue, "loc", "location", "tdb");
- private static ArgDecl argAssemblerDecl = new ArgDecl(ArgDecl.HasValue, "desc", "dataset");
// RDFS vocabulary applied to command line defined dataset.
private static ArgDecl argRDFS = new ArgDecl(ArgDecl.HasValue, "rdfs");
@@ -87,6 +86,7 @@ public class FusekiCmd {
private static ArgDecl argFusekiConfig = new ArgDecl(ArgDecl.HasValue, "config", "conf");
private static ArgDecl argJettyConfig = new ArgDecl(ArgDecl.HasValue, "jetty-config", "jetty");
private static ArgDecl argGZip = new ArgDecl(ArgDecl.HasValue, "gzip");
+ private static ArgDecl argContextPath = new ArgDecl(ArgDecl.HasValue, "pathBase", "contextPath");
// Deprecated. Use shiro.
private static ArgDecl argBasicAuth = new ArgDecl(ArgDecl.HasValue, "basic-auth");
@@ -130,10 +130,6 @@ public class FusekiCmd {
add(argMemTDB, "--memTDB",
"Create an in-memory, non-persistent dataset using TDB (testing only)");
- // This has proven confusing because it is like --conf.
-// add(argAssemblerDecl, "--desc",
-// "Assembler description of a single database");
-
add(argRDFS, "--rdfs=FILE",
"Apply RDFS on top of the dataset");
add(argPort, "--port",
@@ -145,10 +141,13 @@ public class FusekiCmd {
"Global timeout applied to queries (value in ms) -- format is X[,Y] ");
add(argUpdate, "--update",
"Allow updates (via SPARQL Update and SPARQL HTTP Update)");
+ add(argContextPath, "--contextPath=PATH",
+ "Set up the server context (root) path");
add(argFusekiConfig, "--config=",
"Use a configuration file to determine the services");
add(argJettyConfig, "--jetty-config=FILE",
- "Set up the server (not services) with a Jetty XML file");
+ "Set up the server (not services) with a Jetty XML file");
+
add(argBasicAuth);
add(argGZip, "--gzip=on|off",
"Enable GZip compression (HTTP Accept-Encoding) if request header set");
@@ -194,8 +193,6 @@ public class FusekiCmd {
x++;
if ( contains(argFile) )
x++;
- if ( contains(argAssemblerDecl) )
- x++;
if ( contains(argTDB) )
x++;
if ( contains(argMemTDB) )
@@ -353,6 +350,10 @@ public class FusekiCmd {
}
}
+ if ( contains(argContextPath) ) {
+ jettyServerConfig.contextPath = getValue(argContextPath);
+ }
+
if ( contains(argJettyConfig) ) {
jettyServerConfig.jettyConfigFile = getValue(argJettyConfig);
if ( !FileOps.exists(jettyServerConfig.jettyConfigFile) )
diff --git a/jena-fuseki2/jena-fuseki-webapp/src/main/java/org/apache/jena/fuseki/cmd/JettyFusekiWebapp.java b/jena-fuseki2/jena-fuseki-webapp/src/main/java/org/apache/jena/fuseki/cmd/JettyFusekiWebapp.java
index 7361725d2f..825359e1d0 100644
--- a/jena-fuseki2/jena-fuseki-webapp/src/main/java/org/apache/jena/fuseki/cmd/JettyFusekiWebapp.java
+++ b/jena-fuseki2/jena-fuseki-webapp/src/main/java/org/apache/jena/fuseki/cmd/JettyFusekiWebapp.java
@@ -44,7 +44,6 @@ import org.eclipse.jetty.util.resource.ResourceFactory;
import org.eclipse.jetty.xml.XmlConfiguration;
/** Standalone full server, not run as a WAR file.
- * Used in testing and development.
*
* SPARQLServer is the Jena server instance which wraps/utilizes
* {@link org.eclipse.jetty.server.Server}. This class provides
@@ -73,11 +72,10 @@ public class JettyFusekiWebapp {
private Server server = null;
private ServletContext servletContext = null;
- // webapp setup - standard maven layout
- public static String contextpath = "/";
- // Standalone jar
+ // Location of webapp static resources.
+ // -- Standalone jar
public static final String baseResource1 = "webapp";
- // Development
+ // -- Development
public static final String baseResource2 = "target/webapp";
/**
@@ -86,7 +84,6 @@ public class JettyFusekiWebapp {
* name etc.
* @param config
*/
-
public static void initializeServer(JettyServerConfig config) {
instance = new JettyFusekiWebapp(config);
}
@@ -171,6 +168,7 @@ public class JettyFusekiWebapp {
baseResource4 = HOME+"/"+baseResource2;
}
+ // The location in the webapp, not the URL names.
String baseResource = tryBaseResource(baseResource1, null);
baseResource = tryBaseResource(baseResource2, baseResource);
baseResource = tryBaseResource(baseResource3, baseResource);
@@ -186,8 +184,8 @@ public class JettyFusekiWebapp {
}
webapp.setDescriptor(baseResource+"/WEB-INF/web.xml");
- webapp.getContext().getServletContextHandler().setBaseResourceAsString(baseResource);
webapp.setContextPath(contextPath);
+ webapp.getContext().getServletContextHandler().setBaseResourceAsString(baseResource);
//-- Jetty setup for the ServletContext logger.
// The name of the Jetty-allocated slf4j/log4j logger is
@@ -275,30 +273,7 @@ public class JettyFusekiWebapp {
securityHandler.addConstraintMapping(mapping);
context.setSecurityHandler(securityHandler);
-
-// Constraint constraint = new Constraint();
-// constraint.setName(Constraint.__BASIC_AUTH);
-// constraint.setRoles(new String[]{"fuseki"});
-// constraint.setAuthenticate(true);
-//
-// ConstraintMapping mapping = new ConstraintMapping();
-// mapping.setConstraint(constraint);
-// mapping.setPathSpec("/*");
-//
-// IdentityService identService = new DefaultIdentityService();
-//
-// securityHandler.addConstraintMapping(mapping);
-// securityHandler.setIdentityService(identService);
-//
-// HashLoginService loginService = new HashLoginService("Fuseki Authentication", authfile);
-// loginService.setIdentityService(identService);
-//
-// securityHandler.setLoginService(loginService);
-// securityHandler.setAuthenticator(new BasicAuthenticator());
-//
-// context.setSecurityHandler(securityHandler);
-//
-// serverLog.debug("Basic Auth Configuration = " + authfile);
+ serverLog.debug("Basic Auth Configuration = " + authfile);
}
/**
@@ -322,21 +297,10 @@ public class JettyFusekiWebapp {
return ResourceFactory.root().newResource(filename);
}
- private void configServer(String jettyConfig) {
- try {
- serverLog.info("Jetty server config file = " + jettyConfig);
- server = new Server();
- Resource configXml = ResourceFactory.root().newResource(jettyConfig);
- XmlConfiguration configuration = new XmlConfiguration(configXml);
- configuration.configure(server);
- serverConnector = (ServerConnector)server.getConnectors()[0];
- } catch (Exception ex) {
- serverLog.error("SPARQLServer: Failed to configure server: " + ex.getMessage(), ex);
- throw new FusekiException("Failed to configure a server using configuration file '" + jettyConfig + "'");
- }
- }
-
private void defaultServerConfig(int port, boolean loopback) {
+ // At least 3.
+// ThreadPool threadPool = new QueuedThreadPool(4);
+// server = new Server(threadPool);
server = new Server();
HttpConnectionFactory f1 = new HttpConnectionFactory();
// Some people do try very large operations ... really, should use POST.
@@ -357,4 +321,18 @@ public class JettyFusekiWebapp {
connector.setHost("localhost");
serverConnector = connector;
}
+
+ private void configServer(String jettyConfig) {
+ try {
+ serverLog.info("Jetty server config file = " + jettyConfig);
+ server = new Server();
+ Resource configXml = ResourceFactory.root().newResource(jettyConfig);
+ XmlConfiguration configuration = new XmlConfiguration(configXml);
+ configuration.configure(server);
+ serverConnector = (ServerConnector)server.getConnectors()[0];
+ } catch (Exception ex) {
+ serverLog.error("SPARQLServer: Failed to configure server: " + ex.getMessage(), ex);
+ throw new FusekiException("Failed to configure a server using configuration file '" + jettyConfig + "'");
+ }
+ }
}