Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@

import java.io.FileInputStream ;

import javax.servlet.ServletContext ;

import org.apache.jena.atlas.lib.DateTimeUtils ;
import org.apache.jena.atlas.lib.FileOps ;
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.DataAccessPointRegistry ;
import org.apache.jena.fuseki.server.FusekiEnv ;
import org.eclipse.jetty.security.* ;
import org.eclipse.jetty.security.authentication.BasicAuthenticator ;
Expand Down Expand Up @@ -66,7 +69,9 @@ public class JettyFuseki {
private JettyServerConfig serverConfig ;

// The jetty server.

private Server server = null ;
private ServletContext servletContext = null ;

// webapp setup - standard maven layout
public static String contextpath = "/" ;
Expand Down Expand Up @@ -218,6 +223,10 @@ public static String getenv(String name) {
x = System.getProperty(name) ;
return x ;
}

public DataAccessPointRegistry getDataAccessPointRegistry() {
return DataAccessPointRegistry.get(servletContext) ;
}

private static String tryResourceBase(String maybeResourceBase, String currentResourceBase) {
if ( currentResourceBase != null )
Expand All @@ -236,6 +245,7 @@ private void buildServerWebapp(String contextPath, String jettyConfig) {
defaultServerConfig(serverConfig.port, serverConfig.loopback) ;

WebAppContext webapp = createWebApp(contextPath) ;
servletContext = webapp.getServletContext() ;
server.setHandler(webapp) ;
// Replaced by Shiro.
if ( jettyConfig == null && serverConfig.authConfigFile != null )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.servlet.ServletContext ;

import org.apache.jena.atlas.lib.Registry ;
import org.apache.jena.atlas.logging.Log ;
import org.apache.jena.fuseki.FusekiException ;

public class DataAccessPointRegistry extends Registry<String, DataAccessPoint>
Expand Down Expand Up @@ -49,22 +50,19 @@ public void print(String string) {
});
}) ;
}

// TODO To be removed ...
private static DataAccessPointRegistry singleton = new DataAccessPointRegistry() ;
// Still used by ServerTest and FusekiEmbeddedServer (but nowhere else)
public static DataAccessPointRegistry get() { return singleton ; }

// The server DataAccessPointRegistry is held in the ServletContext for the server.

private static final String attrNameRegistry = "jena-fuseki:dataAccessPointRegistry" ;
// Policy for the location of the server-wide DataAccessPointRegistry
public static DataAccessPointRegistry get(ServletContext cxt) {
//return (DataAccessPointRegistry)cxt.getAttribute(attrName) ;
return singleton ;
DataAccessPointRegistry registry = (DataAccessPointRegistry)cxt.getAttribute(attrNameRegistry) ;
if ( registry == null )
Log.warn(DataAccessPointRegistry.class, "No registry for ServletContext") ;
return registry ;
}

public static void set(ServletContext cxt, DataAccessPointRegistry registry) {
// Temporary until get() removed completely.
singleton = registry ;
cxt.setAttribute(attrNameRegistry, registry) ;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ public void contextInitialized(ServletContextEvent sce) {
String x = servletContext.getContextPath() ;
if ( ! x.isEmpty() )
Fuseki.configLog.info("Context path = "+x) ;
// String x = System.getProperty("user.dir") ;
// Path currentRelativePath = Paths.get("");
// String s = currentRelativePath.toAbsolutePath().toString();
// confLog.info("dir1 = "+x+" : dir2 = "+s) ;

// Set the server wide state.
//servletContext.setAttribute(, DataAccessPointRegistry.get()) ;
serverInitialization(servletContext) ;
}

Expand All @@ -72,6 +65,9 @@ private synchronized void serverInitialization(ServletContext servletContext) {
return ;
initialized = true ;

DataAccessPointRegistry registry = new DataAccessPointRegistry() ;
DataAccessPointRegistry.set(servletContext, registry);

try {
FusekiServer.formatBaseArea() ;
if ( ! FusekiServer.serverInitialized ) {
Expand All @@ -88,7 +84,7 @@ private synchronized void serverInitialization(ServletContext servletContext) {
}

if ( initialSetup != null ) {
FusekiServer.initializeDataAccessPoints(DataAccessPointRegistry.get(servletContext),
FusekiServer.initializeDataAccessPoints(registry,
initialSetup, FusekiServer.dirConfiguration.toString()) ;
} else {
Fuseki.serverLog.error("No configuration") ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@
import java.io.IOException ;
import java.net.ServerSocket ;
import java.nio.file.Paths ;
import java.util.Collection ;
import java.util.concurrent.atomic.AtomicInteger ;

import org.apache.http.client.HttpClient ;
import org.apache.http.impl.client.CloseableHttpClient ;
import org.apache.jena.atlas.io.IO ;
import org.apache.jena.atlas.iterator.Iter ;
import org.apache.jena.atlas.lib.FileOps ;
import org.apache.jena.fuseki.jetty.JettyFuseki ;
import org.apache.jena.fuseki.jetty.JettyServerConfig ;
Expand Down Expand Up @@ -240,15 +238,13 @@ public static void setupServer(int port, String authConfigFile, String datasetPa
}

/*package*/ static void teardownServer() {
if ( server != null )
if ( server != null ) {
// Clear out the registry.
server.getDataAccessPointRegistry().clear() ;
FileOps.clearAll(FusekiServer.dirConfiguration.toFile()) ;
server.stop() ;
}
server = null ;
// Clear out the registry.
Collection<String> keys = Iter.toList(DataAccessPointRegistry.get().keys().iterator()) ;
for (String k : keys)
DataAccessPointRegistry.get().remove(k) ;
// Clear configuration directory.
FileOps.clearAll(FusekiServer.dirConfiguration.toFile()) ;
}

/*package*/ static JettyServerConfig make(int port, boolean allowUpdate, boolean listenLocal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,23 @@ public ServletContext getServletContext() {
return ((ServletContextHandler)server.getHandler()).getServletContext() ;
}

/** Get the {@link DataAccessPointRegistry}.
* This method is intended for inspecting the registry.
*/
public DataAccessPointRegistry getDataAccessPointRegistry() {
return DataAccessPointRegistry.get(getServletContext()) ;
}

/** Start the server - the server continues to run after this call returns.
* To synchronise with the server stopping, call {@link #join}.
*/
public void start() {
public FusekiEmbeddedServer start() {
try { server.start(); }
catch (Exception e) { throw new FusekiException(e) ; }
if ( port == 0 )
port = ((ServerConnector)server.getConnectors()[0]).getLocalPort() ;
Fuseki.serverLog.info("Start Fuseki (port="+port+")");
return this ;
}

/** Stop the server. */
Expand Down
Loading