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 2014/02/22 19:16:42 UTC
svn commit: r1570871 - in /jena/branches/jena-fuseki-new-ui: ./
src/main/java/org/apache/jena/fuseki/
src/main/java/org/apache/jena/fuseki/jetty/
src/main/java/org/apache/jena/fuseki/mgt/
src/test/java/org/apache/jena/fuseki/
Author: andy
Date: Sat Feb 22 18:16:42 2014
New Revision: 1570871
URL: http://svn.apache.org/r1570871
Log:
Improved fuseki service script (JENA-635)
Added:
jena/branches/jena-fuseki-new-ui/fuseki_d.sh
Modified:
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/FusekiCmd.java
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/jetty/SPARQLServer.java
jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/mgt/ActionDescription.java
jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/ServerTest.java
Added: jena/branches/jena-fuseki-new-ui/fuseki_d.sh
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/fuseki_d.sh?rev=1570871&view=auto
==============================================================================
--- jena/branches/jena-fuseki-new-ui/fuseki_d.sh (added)
+++ jena/branches/jena-fuseki-new-ui/fuseki_d.sh Sat Feb 22 18:16:42 2014
@@ -0,0 +1,429 @@
+#!/usr/bin/env bash
+
+# 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.
+#
+# =========
+#
+# Startup script for Fuseki under *nix systems (works with cygwin too)
+#
+# Configuration
+# -------------
+# Default values are loaded from /etc/default/fuseki, if it exists.
+#
+# JAVA
+# Command to invoke Java. If not set, java (from the PATH) will be used.
+#
+# JAVA_OPTIONS
+# Extra options to pass to the JVM.
+#
+# FUSEKI_HOME
+# Where Fuseki is installed. If not set, the script will try
+# to guess it based on the script invokation path.
+#
+# FUSEKI_RUN
+# Where the fuseki.pid file should be stored. It defaults
+# first available of /var/run, /usr/var/run, and /tmp if not set.
+#
+# FUSEKI_PID
+# The FUSEKI PID file, defaults to $FUSEKI_RUN/fuseki.pid
+#
+# FUSEKI_ARGS
+# The arguments to pass to the Fuseki server on the command line. Defaults to:
+# --update --loc=$FUSKEI_DATA_DIR /ds # if FUSEKI_CONF is not set
+# --config=$FUSEKI_CONF # if FUSEKI_CONF is set
+#
+# FUSEKI_CONF
+# The Fuseki configuration file, usually in RDF Turtle notation.
+#
+# FUSEKI_USER
+# If set, the server will be run as this user
+#
+# FUSEKI_DATA_DIR
+# The location of the data directory Fuseki will use (i.e. the value of --loc).
+# Defaults to $FUSEKI_HOME/DB
+#
+# FUSEKI_LOGS
+# Directory where logs will be generated. Defaults to $FUSEKI_HOME/log
+#
+# FUSEKI_LOGS_STDERROUT
+# Log file with stderr and stdout log output from Fuseki. Defaults to
+# $FUSEKI_LOGS/stderrout.log
+
+### BEGIN INIT INFO
+# Provides: fuseki
+# Required-Start: $remote_fs $network
+# Required-Stop: $remote_fs $network
+# Default-Start: 3 4 5
+# Default-Stop: 0 1 2 6
+# Short-Description: Start Jena Fuseki at boot time
+# Description: Jena Fuseki is a service that provides a SPARQL API over HTTP to one more RDF triple stores
+### END INIT INFO
+
+# DEBUG=1
+NAME=fuseki
+if [ -f /etc/default/$NAME ]; then
+ . /etc/default/$NAME
+fi
+
+if [ -f /lib/lsb/init-functions ]; then
+ . /lib/lsb/init-functions
+else
+ # simple replacements for LSB daemon logging functions if not defined
+ log_daemon_msg() {
+ echo $1
+ }
+ log_begin_msg() {
+ echo $1
+ }
+ log_end_msg() {
+ if [ $1 -eq 0]; then
+ echo '[OK]'
+ else
+ echo '[failed]'
+ fi
+ }
+fi
+
+usage()
+{
+ echo "Usage: ${0##*/} {start|stop|restart|status}"
+ exit 1
+}
+
+[ $# -gt 0 ] || usage
+
+# Utility functions
+
+findDirectory()
+{
+ local L OP=$1
+ shift
+ for L in "$@"; do
+ [ "$OP" "$L" ] || continue
+ printf %s "$L"
+ break
+ done
+}
+
+findFile()
+{
+ local L F=$1
+ shift
+ for L in "$@"; do
+ [ -f "${L}/${F}" ] || continue
+ printf %s "${L}/${F}"
+ break
+ done
+}
+
+running()
+{
+ local PID=$(cat "$1" 2>/dev/null) || return 1
+ ps -p "$PID" >/dev/null 2>&1
+}
+
+# Are we running in cygwin?
+cygwin=false
+case "`uname`" in
+ CYGWIN*) cygwin=true;;
+esac
+
+
+# Set FUSKEI_HOME to the script invocation directory if it is not specified
+if [ -z "$FUSEKI_HOME" ]
+then
+ SCRIPT="$0"
+ # Catch common issue: script has been symlinked
+ if [ -L "$SCRIPT" ]
+ then
+ SCRIPT="$(readlink "$0")"
+ # If link is relative
+ case "$SCRIPT" in
+ /*) ;; # fine
+ *) SCRIPT=$( dirname "$0" )/$SCRIPT;; # fix
+ esac
+ fi
+
+ # Work out root from script location
+ FUSEKI_HOME="$( cd "$( dirname "$SCRIPT" )" && pwd )"
+
+fi
+
+# Deal with more Cygwin path issues
+if [ "$cygwin" == "true" ]
+then
+ FUSEKI_HOME=`cygpath -w "$FUSEKI_HOME"`
+ fi
+
+if [ ! -e "$FUSEKI_HOME" ]
+then
+ log_daemon_message "$FUSEKI_HOME does not exist" 1>&2
+ exit 1
+fi
+
+
+# Find a location for the pid file
+if [ -z "$FUSEKI_RUN" ]
+then
+ FUSEKI_RUN=$(findDirectory -w /var/run /usr/var/run $FUSEKI_HOME /tmp)
+fi
+
+# Get PID file name
+if [ -z "$FUSEKI_PID" ]
+then
+ FUSEKI_PID="$FUSEKI_RUN/fuseki.pid"
+fi
+
+# Log directory
+if [ -z "$FUSEKI_LOGS" ]
+then
+ FUSEKI_LOGS="$FUSEKI_HOME/log"
+fi
+
+# Std Err and Out log
+if [ -z "$FUSEKI_LOGS_STDERROUT" ]
+then
+ FUSEKI_LOGS_STDERROUT="$FUSEKI_LOGS/stderrout.log"
+fi
+
+# Data directory
+if [ -z "$FUSEKI_DATA_DIR" ]
+then
+ FUSEKI_DATA_DIR="$FUSEKI_HOME/DB"
+fi
+
+# Set up JAVA if not set
+if [ -z "$JAVA" ]
+then
+ JAVA=$(which java)
+fi
+if [ -z "$JAVA" ]
+then
+ echo "Cannot find a Java JDK. Please set either set JAVA or put java (>=1.6) in your PATH." 2>&2
+ exit 1
+fi
+
+# The location of the start up JAR
+FUSEKI_START=${FUSEKI_START:-$FUSEKI_HOME/fuseki-server.jar}
+
+# Deal with Cygwin path issues
+if [ "$cygwin" == "true" ]
+then
+ DATA_DIR=`cygpath -w "$FUSEKI_DATA_DIR"`
+ FUSEKI_START=`cygpath -w "$FUSEKI_START"`
+else
+ DATA_DIR="$FUSEKI_DATA_DIR"
+fi
+
+# Some JVM settings
+if [ -z "$JAVA_OPTIONS" ]
+then
+ JAVA_OPTIONS="-Xmx1200M"
+fi
+
+
+# Default Fuseki Arguments
+if [ -z "$FUSEKI_ARGS" ]
+then
+ if [ -z "$FUSEKI_CONF" ]
+ then
+ FUSEKI_ARGS="--update --loc=$DATA_DIR /ds"
+ else
+ FUSEKI_ARGS="--config=$FUSEKI_CONF"
+ fi
+fi
+
+# Run command
+
+RUN_ARGS=(${JAVA_OPTIONS[@]} -jar "$FUSEKI_START" $FUSEKI_ARGS)
+RUN_CMD=("$JAVA" ${RUN_ARGS[@]})
+
+
+#####################################################
+# Comment these out after you're happy with what
+# the script is doing.
+#####################################################
+if (( DEBUG ))
+then
+ log_daemon_msg "FUSEKI_HOME = $FUSEKI_HOME"
+ log_daemon_msg "FUSEKI_CONF = $FUSEKI_CONF"
+ log_daemon_msg "FUSEKI_RUN = $FUSEKI_RUN"
+ log_daemon_msg "FUSEKI_PID = $FUSEKI_PID"
+ log_daemon_msg "FUSEKI_ARGS = $FUSEKI_ARGS"
+ log_daemon_msg "FUSEKI_START = $FUSEKI_START"
+ log_daemon_msg "CONFIGS = ${CONFIGS[*]}"
+ log_daemon_msg "JAVA = $JAVA"
+ log_daemon_msg "JAVA_OPTIONS = ${JAVA_OPTIONS[*]}"
+ log_daemon_msg "RUN_ARGS = ${RUN_ARGS[@]}"
+ log_daemon_msg "RUN_CMD = ${RUN_CMD[@]}"
+fi
+
+NO_START=0
+
+# Life cycle functions
+start() {
+ if (( NO_START )); then
+ log_daemon_msg "Not starting Fuseki - NO_START=1"
+ exit
+ fi
+
+ # Make sure the data and log directories exist
+ mkdir -p "$FUSEKI_DATA_DIR"
+ mkdir -p "$FUSEKI_LOGS"
+
+ # Make sure the .jar file exists
+ if [ ! -e $FUSEKI_START ]; then
+ log_daemon_msg "Could not see Fuseki .jar file: \$FUSEKI_START has value '$FUSEKI_START'"
+ exit 1
+ fi
+
+ log_begin_msg "Starting Fuseki"
+ if type start-stop-daemon > /dev/null 2>&1
+ then
+ unset CH_USER
+ if [ -n "$FUSEKI_USER" ]
+ then
+ CH_USER="--chuid $FUSEKI_USER"
+ fi
+ if start-stop-daemon --start $CH_USER --chdir "$FUSEKI_HOME" --background --make-pidfile --pidfile "$FUSEKI_PID" --startas "$JAVA" -- "${RUN_ARGS[@]}"
+ then
+ sleep 2
+ if running "$FUSEKI_PID"
+ then
+ log_end_msg 0
+ print_started
+ else
+ log_end_msg 1
+ fi
+ else
+ log_end_msg 1
+ log_daemon_msg "** start-stop-daemon failed to run"
+ fi
+ else
+ if running $FUSEKI_PID
+ then
+ log_end_msg 1
+ log_daemon_msg 'Already Running!'
+ exit 1
+ else
+ # dead pid file - remove
+ rm -f "$FUSEKI_PID"
+ fi
+
+ if [ "$FUSEKI_USER" ]
+ then
+ touch "$FUSEKI_PID"
+ chown "$FUSEKI_USER" "$FUSEKI_PID"
+ su - "$FUSEKI_USER" -c "
+ log_daemon_msg "Redirecting Fuseki stderr/stdout to $FUSEKI_LOGS_STDERROUT"
+ exec ${RUN_CMD[*]} &
+ disown \$!
+ echo \$! > '$FUSEKI_PID'"
+ else
+ #log_daemon_msg "Redirecting Fuseki stderr/stdout to $FUSEKI_LOGS_STDERROUT"
+ exec "${RUN_CMD[@]}" &> "$FUSEKI_LOGS_STDERROUT" &
+ disown $!
+ echo $! > "$FUSEKI_PID"
+ fi
+
+ log_end_msg 0
+ print_started
+ fi
+}
+
+print_started() {
+ log_daemon_msg "STARTED Fuseki `date`"
+ log_daemon_msg "PID=$(cat "$FUSEKI_PID" 2>/dev/null)"
+}
+
+delete_fuseki_pid_file() {
+ rm -f "$FUSEKI_PID"
+}
+
+stop() {
+ log_begin_msg "Stopping Fuseki: "
+
+ if ! running "$FUSEKI_PID"
+ then
+ log_end_msg 1
+
+ # if a stop rather than a restart, signal failure to stop
+ if [ -z "$1" ]
+ then
+ exit 1
+ fi
+ fi
+
+ ###############################################################
+ # !!!! This code needs to be improved, too many repeats !!!! #
+ ###############################################################
+ if type start-stop-daemon > /dev/null 2>&1; then
+ start-stop-daemon --stop --pidfile "$FUSEKI_PID" --chdir "$FUSEKI_HOME" --startas "$JAVA" --signal HUP
+
+ ## Die after a 30 second timeout
+ TIMEOUT=30
+ while running "$FUSEKI_PID"; do
+ if (( TIMEOUT-- == 0 )); then
+ start-stop-daemon --stop --pidfile "$FUSEKI_PID" --chdir "$FUSEKI_HOME" --startas "$JAVA" --signal KILL
+ fi
+ sleep 1
+ done
+ delete_fuseki_pid_file
+ log_end_msg 0
+ else
+ PID=$(cat "$FUSEKI_PID" 2>/dev/null)
+ kill "$PID" 2>/dev/null
+
+ TIMEOUT=30
+ while running $FUSEKI_PID; do
+ if (( TIMEOUT-- == 0 )); then
+ kill -KILL "$PID" 2>/dev/null
+ fi
+ sleep 1
+ done
+ delete_fuseki_pid_file
+ log_end_msg 0
+ fi
+}
+
+case $1 in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ restart)
+ stop "restarting"
+ start
+ ;;
+ status)
+ FUSEKI_PID=$(findFile fuseki.pid /var/run /usr/var/run $FUSEKI_HOME /tmp)
+ if running $FUSEKI_PID
+ then
+ PID=`cat "$FUSEKI_PID"`
+ log_daemon_msg "Fuseki is running with pid: $PID"
+ else
+ log_daemon_msg "Fuseki is not running"
+ fi
+ ;;
+ *)
+ usage
+ ;;
+esac
+
+exit 0
Modified: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/FusekiCmd.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/FusekiCmd.java?rev=1570871&r1=1570870&r2=1570871&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/FusekiCmd.java (original)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/FusekiCmd.java Sat Feb 22 18:16:42 2014
@@ -18,25 +18,20 @@
package org.apache.jena.fuseki ;
-import java.io.File ;
-import java.net.URL ;
import java.util.List ;
import org.apache.jena.atlas.lib.FileOps ;
import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.lib.StrUtils ;
import org.apache.jena.fuseki.build.Template ;
-import org.apache.jena.fuseki.server.FusekiServletContextListener ;
-import org.apache.jena.fuseki.server.ServerInitialConfig ;
import org.apache.jena.fuseki.jetty.JettyServerConfig ;
import org.apache.jena.fuseki.jetty.SPARQLServer ;
+import org.apache.jena.fuseki.server.FusekiServletContextListener ;
+import org.apache.jena.fuseki.server.ServerInitialConfig ;
import org.apache.jena.riot.Lang ;
import org.apache.jena.riot.RDFDataMgr ;
import org.apache.jena.riot.RDFLanguages ;
-import org.apache.jena.riot.SysRIOT ;
-import org.apache.log4j.PropertyConfigurator ;
-import org.apache.log4j.helpers.Loader ;
import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
import arq.cmd.CmdException ;
import arq.cmdline.ArgDecl ;
import arq.cmdline.CmdARQ ;
@@ -49,430 +44,318 @@ import com.hp.hpl.jena.tdb.TDB ;
import com.hp.hpl.jena.tdb.sys.Names ;
import com.hp.hpl.jena.tdb.transaction.TransactionManager ;
-public class FusekiCmd extends CmdARQ {
- private static String log4Jsetup = StrUtils.strjoinNL
- ("## Plain output to stdout",
- "log4j.appender.jena.plainstdout=org.apache.log4j.ConsoleAppender",
- "log4j.appender.jena.plainstdout.target=System.out",
- "log4j.appender.jena.plainstdout.layout=org.apache.log4j.PatternLayout",
- "log4j.appender.jena.plainstdout.layout.ConversionPattern=%d{HH:mm:ss} %-10c{1} %-5p %m%n",
-
- "## Plain output to stderr",
- "log4j.appender.jena.plainstderr=org.apache.log4j.ConsoleAppender",
- "log4j.appender.jena.plainstderr.target=System.err",
- "log4j.appender.jena.plainstderr.layout=org.apache.log4j.PatternLayout",
- "log4j.appender.jena.plainstderr.layout.ConversionPattern=%d{HH:mm:ss} %-10c{1} %-5p %m%n",
-
- "## Everything",
- "log4j.rootLogger=INFO, jena.plainstdout",
- "log4j.logger.com.hp.hpl.jena=WARN",
- "log4j.logger.org.openjena=WARN",
- "log4j.logger.org.apache.jena=WARN",
-
- "log4j.logger.org.apache.jena=WARN",
-
- "# System logs.",
- "log4j.logger." + Fuseki.serverLogName + "=INFO",
- "log4j.logger." + Fuseki.requestLogName + "=INFO",
- "log4j.logger." + Fuseki.adminLogName + "=INFO",
- "log4j.logger." + Fuseki.validationLogName + "=INFO",
- "log4j.logger." + Fuseki.configLogName + "=INFO",
-
- "log4j.logger.org.apache.jena.tdb.loader=INFO",
- "log4j.logger.org.eclipse.jetty=WARN" ,
- "log4j.logger.org.apache.shiro=WARN",
-
- "## Parser output",
- "log4j.additivity" + SysRIOT.riotLoggerName + "=false",
- "log4j.logger." + SysRIOT.riotLoggerName + "=INFO, jena.plainstdout"
- ) ;
-
- // Set logging.
- // 1/ Use log4j.configuration is defined.
- // 2/ Use file:log4j.properties
- // 3/ Use Built in.
-
- public static void setLogging() {
- // No loggers have been created but configuration may have been set up.
- String x = System.getProperty("log4j.configuration", null) ;
-
- if ( x != null && !x.equals("set") ) {
- // "set" indicates that CmdMain set logging.
- // Use standard log4j initialization.
- return ;
- }
-
- // Look for a log4j.properties in the current working directory for easy customization.
- try {
- String fn = "log4j.properties" ;
- File f = new File(fn) ;
- if ( f.exists() ) {
- System.out.println("File") ;
- // Use file log4j.properties
- System.setProperty("log4j.configuration", "file:" + fn) ;
- return ;
- }
- } catch (Throwable th) {}
-
- // CmdMain will have set logging.
-
- // Use built-in for Fuseki.
-
- // The log4j general is initialization done in a class static in LogManager
- // so it can't be called again in any sensible manner. Instead, we include
- // the same mechanism ...
- try {
- URL url = Loader.getResource("log4j.properties") ;
- PropertyConfigurator.configure(url);
- } catch (Throwable ex) {
- ex.printStackTrace();
- }
-
- // Alt: set wheer from the java-based string.
- //LogCtl.resetLogging(log4Jsetup) ;
- }
-
- static {
- setLogging() ;
- }
-
- // Arguments:
- // --update
-
- // Specific switches:
-
- // --admin=on/off
-
- // --http-update
- // --http-get
-
- // --sparql-query
- // --sparql-update
-
- // pages/validators/
- // pages/control/
- // pages/query/ or /pages/sparql/
-
- private static ArgDecl argMgt = new ArgDecl(ArgDecl.NoValue, "mgt") ;
- private static ArgDecl argMgtPort = new ArgDecl(ArgDecl.HasValue, "mgtPort", "mgtport") ;
- private static ArgDecl argMem = new ArgDecl(ArgDecl.NoValue, "mem") ;
- private static ArgDecl argAllowUpdate = new ArgDecl(ArgDecl.NoValue, "update", "allowUpdate") ;
- private static ArgDecl argFile = new ArgDecl(ArgDecl.HasValue, "file") ;
- private static ArgDecl argMemTDB = new ArgDecl(ArgDecl.NoValue, "memtdb", "memTDB") ;
- private static ArgDecl argTDB = new ArgDecl(ArgDecl.HasValue, "loc", "location") ;
- private static ArgDecl argPort = new ArgDecl(ArgDecl.HasValue, "port") ;
- private static ArgDecl argLocalhost = new ArgDecl(ArgDecl.NoValue, "localhost", "local") ;
- private static ArgDecl argTimeout = new ArgDecl(ArgDecl.HasValue, "timeout") ;
- private static ArgDecl argFusekiConfig = new ArgDecl(ArgDecl.HasValue, "config", "conf") ;
- private static ArgDecl argJettyConfig = new ArgDecl(ArgDecl.HasValue, "jetty-config") ;
- private static ArgDecl argGZip = new ArgDecl(ArgDecl.HasValue, "gzip") ;
-
- // Ignored - it's always dynamic dispatch
- private static ArgDecl argUber = new ArgDecl(ArgDecl.NoValue, "uber", "über") ;
- private static ArgDecl argBasicAuth = new ArgDecl(ArgDecl.HasValue, "basic-auth") ;
-
- private static ArgDecl argHome = new ArgDecl(ArgDecl.HasValue, "home") ;
- private static ArgDecl argPages = new ArgDecl(ArgDecl.HasValue, "pages") ;
-
- // private static ModLocation modLocation = new ModLocation() ;
- private static ModDatasetAssembler modDataset = new ModDatasetAssembler() ;
-
- // fuseki [--mem|--desc assembler.ttl] [--port PORT] **** /datasetURI
+public class FusekiCmd {
+ // This allows us to set logging before calling FusekiCmdInner
+ // FusekiCmdInner inherits from CmdMain which statically sets logging.
+ // By java classloading, super class statics run before the
+ // statics of a class are run.
+ // (Cmd logging should be done lower down but it's normally convenient
+ // to have to set in all circumstances).
+ static { FusekiLogging.setLogging() ; }
static public void main(String... argv) {
- // Just to make sure ...
- ARQ.init() ;
- TDB.init() ;
- Fuseki.init() ;
- new FusekiCmd(argv).mainRun() ;
- }
-
-// /** Port to run the server service on */
-// public int port ;
-// /** Port for the management interface : -1 for no management interface */
-// public int mgtPort ;
-// /** Port for the pages UI : this can be the same as the services port. */
-// public int pagesPort ;
-// /** Jetty config file - if null, use the built-in configuration of Jetty */
-// public String jettyConfigFile = null ;
-// /** Listen only on the loopback (localhost) interface */
-// public boolean loopback = false ;
-// /** The local directory for serving the static pages */
-// public String pages ;
-// /** Enable Accept-Encoding compression. Set to false by default.*/
-// public boolean enableCompression = false ;
-//
-// /** Enable additional logging */
-// public boolean verboseLogging = false ;
-// /**
-// * Authentication config file used to setup Jetty Basic auth, if a Jetty config file was set this is ignored since Jetty config allows much more complex auth methods to be implemented
-// */
-// public String authConfigFile ;
-
- public String homeDir = null ;
- private JettyServerConfig jettyServerConfig = new JettyServerConfig() ;
- {
- jettyServerConfig.port = 3030 ;
- jettyServerConfig.mgtPort = 3031 ;
- jettyServerConfig.pagesPort = jettyServerConfig.port ;
- jettyServerConfig.jettyConfigFile = null ;
- jettyServerConfig.pages = Fuseki.PagesStatic ;
- jettyServerConfig.enableCompression = true ;
- jettyServerConfig.verboseLogging = false ;
+ FusekiCmdInner.main(argv);
}
- private ServerInitialConfig cmdLineDataset = new ServerInitialConfig() ;
-
- public FusekiCmd(String... argv) {
- super(argv) ;
-
- if ( false )
- // Consider ...
- TransactionManager.QueueBatchSize = TransactionManager.QueueBatchSize / 2 ;
-
- getUsage().startCategory("Fuseki") ;
- addModule(modDataset) ;
- add(argMem, "--mem", "Create an in-memory, non-persistent dataset for the server") ;
- add(argFile, "--file=FILE",
- "Create an in-memory, non-persistent dataset for the server, initialised with the contents of the file") ;
- add(argTDB, "--loc=DIR", "Use an existing TDB database (or create if does not exist)") ;
- add(argMemTDB, "--memTDB", "Create an in-memory, non-persistent dataset using TDB (testing only)") ;
- add(argPort, "--port", "Listen on this port number") ;
- add(argPages, "--pages=DIR", "Set of pages to serve as static content") ;
- // Set via jetty config file.
- add(argLocalhost, "--localhost", "Listen only on the localhost interface") ;
- add(argTimeout, "--timeout=", "Global timeout applied to queries (value in ms) -- format is X[,Y] ") ;
- add(argAllowUpdate, "--update", "Allow updates (via SPARQL Update and SPARQL HTTP Update)") ;
- 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") ;
- add(argBasicAuth) ;
- add(argMgt, "--mgt", "Enable the management commands") ;
- add(argMgtPort, "--mgtPort=port", "Port for management optations") ;
- add(argHome, "--home=DIR", "Root of Fuseki installation (overrides environment variable FUSEKI_HOME)") ;
- add(argGZip, "--gzip=on|off", "Enable GZip compression (HTTP Accept-Encoding) if request header set") ;
-
- //add(argUber) ;
- // add(argGSP) ;
-
- super.modVersion.addClass(TDB.class) ;
- super.modVersion.addClass(Fuseki.class) ;
- }
-
- static String argUsage = "[--config=FILE] [--mem|--desc=AssemblerFile|--file=FILE] [--port PORT] /DatasetPathName" ;
-
- @Override
- protected String getSummary() {
- return getCommandName() + " " + argUsage ;
- }
-
- @Override
- protected void processModulesAndArgs() {
- int x = 0 ;
-
- Logger log = Fuseki.serverLog ;
-
- if ( contains(argFusekiConfig) )
- cmdLineDataset.fusekiConfigFile = getValue(argFusekiConfig) ;
-
- ArgDecl assemblerDescDecl = new ArgDecl(ArgDecl.HasValue, "desc", "dataset") ;
-
- // ---- Datasets
-
- if ( contains(argMem) )
- x++ ;
- if ( contains(argFile) )
- x++ ;
- if ( contains(assemblerDescDecl) )
- x++ ;
- if ( contains(argTDB) )
- x++ ;
- if ( contains(argMemTDB) )
- x++ ;
-
- if ( cmdLineDataset.fusekiConfigFile != null ) {
- if ( x > 1 )
- throw new CmdException("Dataset specified on the command line and also a configuration file specified.") ;
- } else {
-// if ( x == 0 )
-// throw new CmdException("Required: either --config=FILE or one of --mem, --file, --loc or --desc") ;
- }
+ static class FusekiCmdInner extends CmdARQ {
+ private static ArgDecl argMgt = new ArgDecl(ArgDecl.NoValue, "mgt") ;
+ private static ArgDecl argMgtPort = new ArgDecl(ArgDecl.HasValue, "mgtPort", "mgtport") ;
+ private static ArgDecl argMem = new ArgDecl(ArgDecl.NoValue, "mem") ;
+ private static ArgDecl argAllowUpdate = new ArgDecl(ArgDecl.NoValue, "update", "allowUpdate") ;
+ private static ArgDecl argFile = new ArgDecl(ArgDecl.HasValue, "file") ;
+ private static ArgDecl argMemTDB = new ArgDecl(ArgDecl.NoValue, "memtdb", "memTDB") ;
+ private static ArgDecl argTDB = new ArgDecl(ArgDecl.HasValue, "loc", "location") ;
+ private static ArgDecl argPort = new ArgDecl(ArgDecl.HasValue, "port") ;
+ private static ArgDecl argLocalhost = new ArgDecl(ArgDecl.NoValue, "localhost", "local") ;
+ private static ArgDecl argTimeout = new ArgDecl(ArgDecl.HasValue, "timeout") ;
+ private static ArgDecl argFusekiConfig = new ArgDecl(ArgDecl.HasValue, "config", "conf") ;
+ private static ArgDecl argJettyConfig = new ArgDecl(ArgDecl.HasValue, "jetty-config") ;
+ private static ArgDecl argGZip = new ArgDecl(ArgDecl.HasValue, "gzip") ;
+
+ // Ignored - it's always dynamic dispatch
+ private static ArgDecl argUber = new ArgDecl(ArgDecl.NoValue, "uber", "über") ;
+ private static ArgDecl argBasicAuth = new ArgDecl(ArgDecl.HasValue, "basic-auth") ;
+
+ private static ArgDecl argHome = new ArgDecl(ArgDecl.HasValue, "home") ;
+ private static ArgDecl argPages = new ArgDecl(ArgDecl.HasValue, "pages") ;
+
+ // private static ModLocation modLocation = new ModLocation() ;
+ private static ModDatasetAssembler modDataset = new ModDatasetAssembler() ;
+
+ // fuseki [--mem|--desc assembler.ttl] [--port PORT] **** /datasetURI
+
+ static public void main(String... argv) {
+ // Just to make sure ...
+ ARQ.init() ;
+ TDB.init() ;
+ Fuseki.init() ;
+ new FusekiCmdInner(argv).mainRun() ;
+ }
+
+ public String homeDir = null ;
+ private JettyServerConfig jettyServerConfig = new JettyServerConfig() ;
+ {
+ jettyServerConfig.port = 3030 ;
+ jettyServerConfig.mgtPort = 3031 ;
+ jettyServerConfig.pagesPort = jettyServerConfig.port ;
+ jettyServerConfig.jettyConfigFile = null ;
+ jettyServerConfig.pages = Fuseki.PagesStatic ;
+ jettyServerConfig.enableCompression = true ;
+ jettyServerConfig.verboseLogging = false ;
+ }
+
+ private ServerInitialConfig cmdLineDataset = new ServerInitialConfig() ;
+
+ public FusekiCmdInner(String... argv) {
+ super(argv) ;
+
+ if ( false )
+ // Consider ...
+ TransactionManager.QueueBatchSize = TransactionManager.QueueBatchSize / 2 ;
+
+ getUsage().startCategory("Fuseki") ;
+ addModule(modDataset) ;
+ add(argMem, "--mem", "Create an in-memory, non-persistent dataset for the server") ;
+ add(argFile, "--file=FILE",
+ "Create an in-memory, non-persistent dataset for the server, initialised with the contents of the file") ;
+ add(argTDB, "--loc=DIR", "Use an existing TDB database (or create if does not exist)") ;
+ add(argMemTDB, "--memTDB", "Create an in-memory, non-persistent dataset using TDB (testing only)") ;
+ add(argPort, "--port", "Listen on this port number") ;
+ add(argPages, "--pages=DIR", "Set of pages to serve as static content") ;
+ // Set via jetty config file.
+ add(argLocalhost, "--localhost", "Listen only on the localhost interface") ;
+ add(argTimeout, "--timeout=", "Global timeout applied to queries (value in ms) -- format is X[,Y] ") ;
+ add(argAllowUpdate, "--update", "Allow updates (via SPARQL Update and SPARQL HTTP Update)") ;
+ 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") ;
+ add(argBasicAuth) ;
+ add(argMgt, "--mgt", "Enable the management commands") ;
+ add(argMgtPort, "--mgtPort=port", "Port for management optations") ;
+ add(argHome, "--home=DIR", "Root of Fuseki installation (overrides environment variable FUSEKI_HOME)") ;
+ add(argGZip, "--gzip=on|off", "Enable GZip compression (HTTP Accept-Encoding) if request header set") ;
+
+ //add(argUber) ;
+ // add(argGSP) ;
+
+ super.modVersion.addClass(TDB.class) ;
+ super.modVersion.addClass(Fuseki.class) ;
+ }
+
+ static String argUsage = "[--config=FILE] [--mem|--desc=AssemblerFile|--file=FILE] [--port PORT] /DatasetPathName" ;
+
+ @Override
+ protected String getSummary() {
+ return getCommandName() + " " + argUsage ;
+ }
+
+ @Override
+ protected void processModulesAndArgs() {
+ int x = 0 ;
+
+ Logger log = Fuseki.serverLog ;
+
+ if ( contains(argFusekiConfig) )
+ cmdLineDataset.fusekiConfigFile = getValue(argFusekiConfig) ;
+
+ ArgDecl assemblerDescDecl = new ArgDecl(ArgDecl.HasValue, "desc", "dataset") ;
+
+ // ---- Datasets
+
+ if ( contains(argMem) )
+ x++ ;
+ if ( contains(argFile) )
+ x++ ;
+ if ( contains(assemblerDescDecl) )
+ x++ ;
+ if ( contains(argTDB) )
+ x++ ;
+ if ( contains(argMemTDB) )
+ x++ ;
+
+ if ( cmdLineDataset.fusekiConfigFile != null ) {
+ if ( x > 1 )
+ throw new CmdException("Dataset specified on the command line and also a configuration file specified.") ;
+ } else {
+ // if ( x == 0 )
+ // throw new CmdException("Required: either --config=FILE or one of --mem, --file, --loc or --desc") ;
+ }
- if ( contains(argMem) ) {
- log.info("Dataset: in-memory") ;
- cmdLineDataset = new ServerInitialConfig() ;
- cmdLineDataset.templateFile = Template.templateMemFN ;
- }
-
- if ( contains(argFile) ) {
- String filename = getValue(argFile) ;
- log.info("Dataset: in-memory: load file: " + filename) ;
- if ( !FileOps.exists(filename) )
- throw new CmdException("File not found: " + filename) ;
-
- // Directly populate the dataset.
- cmdLineDataset = new ServerInitialConfig() ;
- cmdLineDataset.dsg = DatasetGraphFactory.createMem() ;
-
- // INITIAL DATA.
- Lang language = RDFLanguages.filenameToLang(filename) ;
- if ( language == null )
- throw new CmdException("Can't guess language for file: " + filename) ;
- RDFDataMgr.read(cmdLineDataset.dsg, filename) ;
- }
+ if ( contains(argMem) ) {
+ log.info("Dataset: in-memory") ;
+ cmdLineDataset = new ServerInitialConfig() ;
+ cmdLineDataset.templateFile = Template.templateMemFN ;
+ }
- if ( contains(argMemTDB) ) {
- log.info("TDB dataset: in-memory") ;
- cmdLineDataset = new ServerInitialConfig() ;
- cmdLineDataset.templateFile = Template.templateTDBMemFN ;
- }
+ if ( contains(argFile) ) {
+ String filename = getValue(argFile) ;
+ log.info("Dataset: in-memory: load file: " + filename) ;
+ if ( !FileOps.exists(filename) )
+ throw new CmdException("File not found: " + filename) ;
+
+ // Directly populate the dataset.
+ cmdLineDataset = new ServerInitialConfig() ;
+ cmdLineDataset.dsg = DatasetGraphFactory.createMem() ;
+
+ // INITIAL DATA.
+ Lang language = RDFLanguages.filenameToLang(filename) ;
+ if ( language == null )
+ throw new CmdException("Can't guess language for file: " + filename) ;
+ RDFDataMgr.read(cmdLineDataset.dsg, filename) ;
+ }
- if ( contains(argTDB) ) {
- cmdLineDataset = new ServerInitialConfig() ;
- cmdLineDataset.templateFile = Template.templateTDBDirFN ;
-
- String dir = getValue(argTDB) ;
- if ( Lib.equal(dir, Names.memName) ) {
+ if ( contains(argMemTDB) ) {
log.info("TDB dataset: in-memory") ;
- } else {
- if ( !FileOps.exists(dir) )
- throw new CmdException("Directory not found: " + dir) ;
- log.info("TDB dataset: directory=" + dir) ;
+ cmdLineDataset = new ServerInitialConfig() ;
+ cmdLineDataset.templateFile = Template.templateTDBMemFN ;
}
- cmdLineDataset.params.put(Template.DIR, dir) ;
- }
- // Otherwise
- if ( contains(assemblerDescDecl) ) {
- log.info("Dataset from assembler") ;
- // Need to add service details.
- Dataset ds = modDataset.createDataset() ;
- //cmdLineDataset.dsg = ds.asDatasetGraph() ;
- }
+ if ( contains(argTDB) ) {
+ cmdLineDataset = new ServerInitialConfig() ;
+ cmdLineDataset.templateFile = Template.templateTDBDirFN ;
+
+ String dir = getValue(argTDB) ;
+ if ( Lib.equal(dir, Names.memName) ) {
+ log.info("TDB dataset: in-memory") ;
+ } else {
+ if ( !FileOps.exists(dir) )
+ throw new CmdException("Directory not found: " + dir) ;
+ log.info("TDB dataset: directory=" + dir) ;
+ }
+ cmdLineDataset.params.put(Template.DIR, dir) ;
+ }
- if ( cmdLineDataset != null ) {
- if ( getPositional().size() > 1 )
- throw new CmdException("Multiple dataset path names given") ;
- if ( getPositional().size() != 0 ) {
- cmdLineDataset.datasetPath = getPositionalArg(0) ;
- if ( cmdLineDataset.datasetPath.length() > 0 && !cmdLineDataset.datasetPath.startsWith("/") )
- throw new CmdException("Dataset path name must begin with a /: " + cmdLineDataset.datasetPath) ;
- cmdLineDataset.allowUpdate = contains(argAllowUpdate) ;
- // Include the dataset name as NAME for any templates.
- cmdLineDataset.params.put(Template.NAME, cmdLineDataset.datasetPath) ;
+ // Otherwise
+ if ( contains(assemblerDescDecl) ) {
+ log.info("Dataset from assembler") ;
+ // Need to add service details.
+ Dataset ds = modDataset.createDataset() ;
+ //cmdLineDataset.dsg = ds.asDatasetGraph() ;
}
- }
- // ---- Jetty server
- if ( contains(argBasicAuth) )
- Fuseki.configLog.warn("--basic-auth ignored: Use Apache Shiro security - see shiro.ini") ;
-
- if ( contains(argPort) ) {
- String portStr = getValue(argPort) ;
- try {
- jettyServerConfig.port = Integer.parseInt(portStr) ;
- } catch (NumberFormatException ex) {
- throw new CmdException(argPort.getKeyName() + " : bad port number: " + portStr) ;
+ if ( cmdLineDataset != null ) {
+ if ( getPositional().size() > 1 )
+ throw new CmdException("Multiple dataset path names given") ;
+ if ( getPositional().size() != 0 ) {
+ cmdLineDataset.datasetPath = getPositionalArg(0) ;
+ if ( cmdLineDataset.datasetPath.length() > 0 && !cmdLineDataset.datasetPath.startsWith("/") )
+ throw new CmdException("Dataset path name must begin with a /: " + cmdLineDataset.datasetPath) ;
+ cmdLineDataset.allowUpdate = contains(argAllowUpdate) ;
+ // Include the dataset name as NAME for any templates.
+ cmdLineDataset.params.put(Template.NAME, cmdLineDataset.datasetPath) ;
+ }
}
- }
- if ( ! contains(argMgt) && contains(argMgtPort) )
- Fuseki.configLog.warn("Management port specified by admin functions not enabled with --"+argMgt.getKeyName()) ;
-
- if ( contains(argMgt) ) {
- jettyServerConfig.mgtPort = 0 ;
- if ( contains(argMgtPort) ) {
- String mgtPortStr = getValue(argMgtPort) ;
+ // ---- Jetty server
+ if ( contains(argBasicAuth) )
+ Fuseki.configLog.warn("--basic-auth ignored: Use Apache Shiro security - see shiro.ini") ;
+
+ if ( contains(argPort) ) {
+ String portStr = getValue(argPort) ;
try {
- jettyServerConfig.mgtPort = Integer.parseInt(mgtPortStr) ;
+ jettyServerConfig.port = Integer.parseInt(portStr) ;
} catch (NumberFormatException ex) {
- throw new CmdException("--"+argMgtPort.getKeyName() + " : bad port number: " + mgtPortStr) ;
+ throw new CmdException(argPort.getKeyName() + " : bad port number: " + portStr) ;
}
}
- }
- if ( contains(argLocalhost) )
- jettyServerConfig.loopback = true ;
+ if ( ! contains(argMgt) && contains(argMgtPort) )
+ Fuseki.configLog.warn("Management port specified by admin functions not enabled with --"+argMgt.getKeyName()) ;
- if ( contains(argTimeout) ) {
- String str = getValue(argTimeout) ;
- ARQ.getContext().set(ARQ.queryTimeout, str) ;
- }
+ if ( contains(argMgt) ) {
+ jettyServerConfig.mgtPort = 0 ;
+ if ( contains(argMgtPort) ) {
+ String mgtPortStr = getValue(argMgtPort) ;
+ try {
+ jettyServerConfig.mgtPort = Integer.parseInt(mgtPortStr) ;
+ } catch (NumberFormatException ex) {
+ throw new CmdException("--"+argMgtPort.getKeyName() + " : bad port number: " + mgtPortStr) ;
+ }
+ }
+ }
- if ( contains(argJettyConfig) ) {
- jettyServerConfig.jettyConfigFile = getValue(argJettyConfig) ;
- if ( !FileOps.exists(jettyServerConfig.jettyConfigFile) )
- throw new CmdException("No such file: " + jettyServerConfig.jettyConfigFile) ;
- }
+ if ( contains(argLocalhost) )
+ jettyServerConfig.loopback = true ;
- if ( contains(argBasicAuth) ) {
- jettyServerConfig.authConfigFile = getValue(argBasicAuth) ;
- if ( !FileOps.exists(jettyServerConfig.authConfigFile) )
- throw new CmdException("No such file: " + jettyServerConfig.authConfigFile) ;
- }
+ if ( contains(argTimeout) ) {
+ String str = getValue(argTimeout) ;
+ ARQ.getContext().set(ARQ.queryTimeout, str) ;
+ }
- if ( contains(argHome) ) {
- List<String> args = super.getValues(argHome) ;
- homeDir = args.get(args.size() - 1) ;
- }
+ if ( contains(argJettyConfig) ) {
+ jettyServerConfig.jettyConfigFile = getValue(argJettyConfig) ;
+ if ( !FileOps.exists(jettyServerConfig.jettyConfigFile) )
+ throw new CmdException("No such file: " + jettyServerConfig.jettyConfigFile) ;
+ }
- if ( contains(argPages) ) {
- List<String> args = super.getValues(argPages) ;
- jettyServerConfig.pages = args.get(args.size() - 1) ;
- }
+ if ( contains(argBasicAuth) ) {
+ jettyServerConfig.authConfigFile = getValue(argBasicAuth) ;
+ if ( !FileOps.exists(jettyServerConfig.authConfigFile) )
+ throw new CmdException("No such file: " + jettyServerConfig.authConfigFile) ;
+ }
+
+ if ( contains(argHome) ) {
+ List<String> args = super.getValues(argHome) ;
+ homeDir = args.get(args.size() - 1) ;
+ }
+
+ if ( contains(argPages) ) {
+ List<String> args = super.getValues(argPages) ;
+ jettyServerConfig.pages = args.get(args.size() - 1) ;
+ }
- if ( contains(argGZip) ) {
- if ( !hasValueOfTrue(argGZip) && !hasValueOfFalse(argGZip) )
- throw new CmdException(argGZip.getNames().get(0) + ": Not understood: " + getValue(argGZip)) ;
- jettyServerConfig.enableCompression = super.hasValueOfTrue(argGZip) ;
+ if ( contains(argGZip) ) {
+ if ( !hasValueOfTrue(argGZip) && !hasValueOfFalse(argGZip) )
+ throw new CmdException(argGZip.getNames().get(0) + ": Not understood: " + getValue(argGZip)) ;
+ jettyServerConfig.enableCompression = super.hasValueOfTrue(argGZip) ;
+ }
}
- }
- private static String sort_out_dir(String path) {
- path.replace('\\', '/') ;
- if ( !path.endsWith("/") )
- path = path + "/" ;
- return path ;
- }
+ private static String sort_out_dir(String path) {
+ path.replace('\\', '/') ;
+ if ( !path.endsWith("/") )
+ path = path + "/" ;
+ return path ;
+ }
+
+ @Override
+ protected void exec() {
+ Fuseki.init() ;
+ FusekiServletContextListener.initialSetup = cmdLineDataset ;
+ // For standalone, command line use ...
+ SPARQLServer.initializeServer(jettyServerConfig) ;
+ SPARQLServer.instance.start() ;
+ SPARQLServer.instance.join() ;
+ System.exit(0) ;
+ }
+
+ private String pagesDir(String pages) {
+ if ( homeDir == null ) {
+ if ( System.getenv(Fuseki.FusekiHomeEnv) != null )
+ homeDir = System.getenv(Fuseki.FusekiHomeEnv) ;
+ else
+ homeDir = "." ;
+ }
- @Override
- protected void exec() {
- Fuseki.init() ;
- FusekiServletContextListener.initialSetup = cmdLineDataset ;
- // For standalone, command line use ...
- SPARQLServer.initializeServer(jettyServerConfig) ;
- SPARQLServer.instance.start() ;
- try { SPARQLServer.instance.getServer().join() ; }
- catch (Exception ex) {}
- System.exit(0) ;
- }
-
- private String pagesDir(String pages) {
- if ( homeDir == null ) {
- if ( System.getenv(Fuseki.FusekiHomeEnv) != null )
- homeDir = System.getenv(Fuseki.FusekiHomeEnv) ;
- else
- homeDir = "." ;
+ homeDir = sort_out_dir(homeDir) ;
+ Fuseki.configLog.info("Home Directory: " + FileOps.fullDirectoryPath(homeDir)) ;
+ if ( !FileOps.exists(homeDir) )
+ Fuseki.configLog.warn("No such directory for Fuseki home: " + homeDir) ;
+
+ if ( pages == null )
+ pages = homeDir + Fuseki.PagesStatic ;
+
+ Fuseki.configLog.debug("Static Content Directory: " + FileOps.fullDirectoryPath(pages)) ;
+
+ if ( !FileOps.exists(pages) ) {
+ Fuseki.configLog.warn("No such directory for static content: "+ FileOps.fullDirectoryPath(pages)) ;
+ Fuseki.configLog.warn("You may need to set the --pages or --home option to configure static content correctly") ;
+ }
+ return pages ;
}
- homeDir = sort_out_dir(homeDir) ;
- Fuseki.configLog.info("Home Directory: " + FileOps.fullDirectoryPath(homeDir)) ;
- if ( !FileOps.exists(homeDir) )
- Fuseki.configLog.warn("No such directory for Fuseki home: " + homeDir) ;
-
- if ( pages == null )
- pages = homeDir + Fuseki.PagesStatic ;
-
- Fuseki.configLog.debug("Static Content Directory: " + FileOps.fullDirectoryPath(pages)) ;
-
- if ( !FileOps.exists(pages) ) {
- Fuseki.configLog.warn("No such directory for static content: "+ FileOps.fullDirectoryPath(pages)) ;
- Fuseki.configLog.warn("You may need to set the --pages or --home option to configure static content correctly") ;
+ @Override
+ protected String getCommandName() {
+ return "fuseki" ;
}
- return pages ;
- }
-
- @Override
- protected String getCommandName() {
- return "fuseki" ;
}
-}
+}
\ No newline at end of file
Modified: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/jetty/SPARQLServer.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/jetty/SPARQLServer.java?rev=1570871&r1=1570870&r2=1570871&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/jetty/SPARQLServer.java (original)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/jetty/SPARQLServer.java Sat Feb 22 18:16:42 2014
@@ -22,22 +22,13 @@ import static java.lang.String.format ;
import static org.apache.jena.fuseki.Fuseki.serverLog ;
import java.io.FileInputStream ;
-import java.util.Arrays ;
-import java.util.EnumSet ;
-import java.util.List ;
-import javax.servlet.DispatcherType ;
-
-import org.apache.jena.atlas.lib.NotImplemented ;
import org.apache.jena.fuseki.Fuseki ;
import org.apache.jena.fuseki.FusekiException ;
import org.apache.jena.fuseki.mgt.MgtJMX ;
-import org.apache.jena.fuseki.server.FusekiServletContextListener ;
-import org.apache.jena.fuseki.servlets.FusekiFilter ;
import org.eclipse.jetty.security.* ;
import org.eclipse.jetty.security.authentication.BasicAuthenticator ;
import org.eclipse.jetty.server.* ;
-import org.eclipse.jetty.servlet.FilterHolder ;
import org.eclipse.jetty.servlet.ServletContextHandler ;
import org.eclipse.jetty.util.security.Constraint ;
import org.eclipse.jetty.webapp.WebAppContext ;
@@ -55,25 +46,37 @@ import com.hp.hpl.jena.sparql.util.Utils
*/
public class SPARQLServer {
// Jetty specific.
- // All jetty code should be here and in
- static {
- Fuseki.init() ;
- }
+ // This class is becoming less important - it now sets up a Jetty server for in-process use
+ // either for the command line (including the fuskei service init.d script)
+ // or testing but not direct webapp deployments.
+ static { Fuseki.init() ; }
public static SPARQLServer instance = null ;
private ServerConnector serverConnector = null ;
+ // If a separate ...
private ServerConnector mgtConnector = null ;
- private JettyServerConfig serverConfig ;
+ private JettyServerConfig serverConfig ;
+ // The jetty server.
private Server server = null ;
- private static List<String> epDataset = Arrays.asList("*") ;
+
+ // webapp setup.
+ public static final String descriptorFile = "war-web.xml" ;
+ public static final String resourceBase = "pages" ;
+ public static final String contextpath = "/" ;
+
+// public static final String descriptorFile = "src/main/webapp/WEB-INF/web.xml" ;
+// public static final String resourceBase = "src/main/webapp" ;
+// public static final String contextpath = "/" ;
+
+
/**
- * Default constructor which requires a {@link org.apache.jena.fuseki.jetty.JettyServerConfig}
- * object as input. We use this config to specify (verbose) logging, enable compression
- * etc.
+ * Default setup which requires a {@link org.apache.jena.fuseki.jetty.JettyServerConfig}
+ * object as input. We use this config to pass in the command line arguments for dataset,
+ * name etc.
* @param config
*/
@@ -83,21 +86,21 @@ public class SPARQLServer {
instance = new SPARQLServer(config) ;
}
+ /** Build a Jetty server using the development files for the webapp
+ * No command line configuration.
+ */
+ public static Server create(int port) {
+ Server server = new Server(port) ;
+ WebAppContext webapp = createWebApp() ;
+ server.setHandler(webapp) ;
+ return server ;
+ }
+
private SPARQLServer(JettyServerConfig config) {
this.serverConfig = config ;
boolean webappBuild = true ;
- if ( webappBuild )
- buildServerWebapp(serverConfig.jettyConfigFile, config.enableCompression) ;
- else {
- ServletContextHandler context = buildServer(serverConfig.jettyConfigFile, config.enableCompression) ;
- // Filter to grab all request for dynamic dispatching.
- FilterHolder f = new FilterHolder(new FusekiFilter()) ;
- EnumSet<DispatcherType> es = EnumSet.allOf(DispatcherType.class) ;
- context.addFilter(f, "/*", es);
- context.addEventListener(new FusekiServletContextListener());
- // No security.
- }
+ buildServerWebapp(serverConfig.jettyConfigFile, config.enableCompression) ;
if ( mgtConnector == null )
mgtConnector = serverConnector ;
@@ -130,6 +133,16 @@ public class SPARQLServer {
}
/**
+ * Sync with the {@link SPARQLServer} instance.
+ * Returns only if the server exits cleanly
+ */
+ public void join() {
+ try {
+ server.join() ;
+ } catch (InterruptedException ex) { }
+ }
+
+ /**
* Stop the {@link SPARQLServer} instance.
*/
public void stop() {
@@ -143,57 +156,38 @@ public class SPARQLServer {
MgtJMX.removeJMX() ;
}
- /**
- * Get the Jetty instance.
- * @return Server
- */
- public Server getServer() {
- return server ;
- }
-
- public int getServerPort() {
- return serverConnector.getPort() ;
+ public static WebAppContext createWebApp() {
+ WebAppContext webapp = new WebAppContext();
+ webapp.getServletContext().getContextHandler().setMaxFormContentSize(10 * 1000 * 1000) ;
+ webapp.setDescriptor(descriptorFile);
+ webapp.setResourceBase(resourceBase);
+ webapp.setContextPath(contextpath);
+
+ //-- Jetty setup for the ServletContext logger.
+ // The name of the Jetty-allocated slf4j/log4j logger is
+ // the display name or, if null, the context path name.
+ // It is set, without checking for a previous call of setLogger in "doStart"
+ // which happens during server startup.
+ // This the name of the ServletContext logger as well
+ webapp.setDisplayName(Fuseki.serverLogName);
+
+ webapp.setParentLoaderPriority(true); // Normal Java classloader behaviour.
+ webapp.setErrorHandler(new FusekiErrorHandler()) ;
+ return webapp ;
}
-
- public int getMgtPort() {
- return mgtConnector.getPort() ;
- }
-
- private ServletContextHandler buildServerWebapp(String jettyConfig, boolean enableCompression) {
+
+ private void buildServerWebapp(String jettyConfig, boolean enableCompression) {
if ( jettyConfig != null )
// --jetty-config=jetty-fuseki.xml
// for detailed configuration of the server using Jetty features.
configServer(jettyConfig) ;
else
defaultServerConfig(serverConfig.port, serverConfig.loopback) ;
-
- WebAppContext context = new WebAppContext();
- context.getServletContext().getContextHandler().setMaxFormContentSize(10 * 1000 * 1000) ;
- context.setDescriptor("war-web.xml");
- context.setResourceBase("pages");
- context.setContextPath("/");
-
- //-- Jetty setup for the ServletContext logger.
- // The name of the Jetty-allocated slf4j/log4j logger is
- // the display name or, if null, the context path name.
- // It is set, without checking for a previous call of setLogger in "doStart"
- // which happens during server startup.
- // This the name of the ServletContext logger as well
- context.setDisplayName(Fuseki.serverLogName);
-
- context.setParentLoaderPriority(true); // Normal Java classloader behaviour.
- context.setErrorHandler(new FusekiErrorHandler()) ;
- server.setHandler(context) ;
-
+ WebAppContext webapp = createWebApp() ;
+ server.setHandler(webapp) ;
// XXX Security
if ( jettyConfig == null && serverConfig.authConfigFile != null )
- security(context, serverConfig.authConfigFile) ;
-
- return context ;
- }
-
- private ServletContextHandler buildServer(String jettyConfig, boolean enableCompression) {
- throw new NotImplemented("Use the webapps setup") ;
+ security(webapp, serverConfig.authConfigFile) ;
}
private static void security(ServletContextHandler context, String authfile) {
@@ -237,8 +231,6 @@ public class SPARQLServer {
}
private void defaultServerConfig(int port, boolean loopback) {
- // Server, with one NIO-based connector, large input buffer size (for
- // long URLs, POSTed forms (queries, updates)).
server = new Server() ;
ConnectionFactory f1 = new HttpConnectionFactory() ;
ConnectionFactory f2 = new SslConnectionFactory() ;
Modified: jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/mgt/ActionDescription.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/mgt/ActionDescription.java?rev=1570871&r1=1570870&r2=1570871&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/mgt/ActionDescription.java (original)
+++ jena/branches/jena-fuseki-new-ui/src/main/java/org/apache/jena/fuseki/mgt/ActionDescription.java Sat Feb 22 18:16:42 2014
@@ -73,7 +73,7 @@ public class ActionDescription extends A
out.flush() ;
}
- private void describeServer(JsonBuilder builder, int port) {
+ private void describeServer(JsonBuilder builder, int requestPort) {
String versionStr = Fuseki.VERSION ;
String builtDateStr = Fuseki.BUILD_DATE ;
if ( versionStr == null )
@@ -89,7 +89,7 @@ public class ActionDescription extends A
builder
.key(JsonConst.admin)
.startObject()
- .key(JsonConst.port).value(port)
+ .key(JsonConst.port).value(requestPort)
.finishObject() ;
builder
Modified: jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/ServerTest.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/ServerTest.java?rev=1570871&r1=1570870&r2=1570871&view=diff
==============================================================================
--- jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/ServerTest.java (original)
+++ jena/branches/jena-fuseki-new-ui/src/test/java/org/apache/jena/fuseki/ServerTest.java Sat Feb 22 18:16:42 2014
@@ -115,8 +115,7 @@ public class ServerTest {
JettyServerConfig config = make(true, true) ;
config.authConfigFile = authConfigFile ;
SPARQLServer.initializeServer(config);
- server = SPARQLServer.instance ;
- server.start() ;
+ SPARQLServer.instance.start() ;
}
public static JettyServerConfig make(boolean allowUpdate, boolean listenLocal) {