use of org.apache.jena.fuseki.FusekiConfigException in project jena by apache.
the class FusekiConfig method loadAndInit.
private static void loadAndInit(String className) {
try {
Class<?> classObj = Class.forName(className);
log.info("Loaded " + className);
Method initMethod = classObj.getMethod("init");
initMethod.invoke(null);
} catch (ClassNotFoundException ex) {
log.warn("Class not found: " + className);
} catch (Exception e) {
throw new FusekiConfigException(e);
}
}
use of org.apache.jena.fuseki.FusekiConfigException in project jena by apache.
the class FusekiConfig method configure.
public static ServerConfig configure(String filename) {
// Be absolutely sure everything has initialized.
// Some initialization registers assemblers and sets abbreviation vocabulary.
Fuseki.init();
Model m = FileManager.get().loadModel(filename);
// Find one server.
List<Resource> servers = getByType(FusekiVocab.tServer, m);
if (servers.size() == 0)
throw new FusekiConfigException("No server found (no resource with type " + strForResource(FusekiVocab.tServer));
if (servers.size() > 1)
throw new FusekiConfigException(servers.size() + " servers found (must be exactly one in a configuration file)");
// ---- Server
Resource server = servers.get(0);
processServer(server);
// ---- Services
ResultSet rs = query("SELECT * { ?s fu:services [ list:member ?member ] }", m);
if (!rs.hasNext())
log.warn("No services found");
List<DatasetRef> services = new ArrayList<>();
for (; rs.hasNext(); ) {
QuerySolution soln = rs.next();
Resource svc = soln.getResource("member");
DatasetRef sd = processService(svc);
services.add(sd);
}
// TODO Properties for the other fields.
ServerConfig config = new ServerConfig();
config.datasets = services;
config.port = 3030;
config.mgtPort = 3031;
config.pagesPort = config.port;
config.jettyConfigFile = null;
config.pages = Fuseki.PagesStatic;
config.enableCompression = true;
config.verboseLogging = false;
return config;
}
use of org.apache.jena.fuseki.FusekiConfigException in project jena by apache.
the class FusekiConfig method processService.
private static DatasetRef processService(Resource svc) {
log.info("Service: " + nodeLabel(svc));
DatasetRef sDesc = new DatasetRef();
sDesc.name = ((Literal) getOne(svc, "fu:name")).getLexicalForm();
log.info(" name = " + sDesc.name);
addServiceEP("query", sDesc.name, sDesc.query, svc, "fu:serviceQuery");
addServiceEP("update", sDesc.name, sDesc.update, svc, "fu:serviceUpdate");
addServiceEP("upload", sDesc.name, sDesc.upload, svc, "fu:serviceUpload");
addServiceEP("graphStore(RW)", sDesc.name, sDesc.readWriteGraphStore, svc, "fu:serviceReadWriteGraphStore");
addServiceEP("graphStore(R)", sDesc.name, sDesc.readGraphStore, svc, "fu:serviceReadGraphStore");
// Extract timeout overriding configuration if present.
if (svc.hasProperty(FusekiVocab.pAllowTimeoutOverride)) {
sDesc.allowTimeoutOverride = svc.getProperty(FusekiVocab.pAllowTimeoutOverride).getObject().asLiteral().getBoolean();
if (svc.hasProperty(FusekiVocab.pMaximumTimeoutOverride)) {
sDesc.maximumTimeoutOverride = (int) (svc.getProperty(FusekiVocab.pMaximumTimeoutOverride).getObject().asLiteral().getFloat() * 1000);
}
}
Resource datasetDesc = ((Resource) getOne(svc, "fu:dataset"));
// Check if it is in the model.
if (!datasetDesc.hasProperty(RDF.type))
throw new FusekiConfigException("No rdf:type for dataset " + nodeLabel(datasetDesc));
Dataset ds = (Dataset) Assembler.general.open(datasetDesc);
sDesc.dataset = ds.asDatasetGraph();
return sDesc;
}
use of org.apache.jena.fuseki.FusekiConfigException in project jena by apache.
the class FusekiServer method formatBaseArea.
/*package*/
static synchronized void formatBaseArea() {
if (initialized)
return;
initialized = true;
try {
FusekiEnv.setEnvironment();
Path FUSEKI_HOME = FusekiEnv.FUSEKI_HOME;
Path FUSEKI_BASE = FusekiEnv.FUSEKI_BASE;
Fuseki.init();
Fuseki.configLog.info("FUSEKI_HOME=" + ((FUSEKI_HOME == null) ? "unset" : FUSEKI_HOME.toString()));
Fuseki.configLog.info("FUSEKI_BASE=" + FUSEKI_BASE.toString());
if (FUSEKI_HOME != null) {
if (!Files.isDirectory(FUSEKI_HOME))
throw new FusekiConfigException("FUSEKI_HOME is not a directory: " + FUSEKI_HOME);
if (!Files.isReadable(FUSEKI_HOME))
throw new FusekiConfigException("FUSEKI_HOME is not readable: " + FUSEKI_HOME);
}
if (Files.exists(FUSEKI_BASE)) {
if (!Files.isDirectory(FUSEKI_BASE))
throw new FusekiConfigException("FUSEKI_BASE is not a directory: " + FUSEKI_BASE);
if (!Files.isWritable(FUSEKI_BASE))
throw new FusekiConfigException("FUSEKI_BASE is not writable: " + FUSEKI_BASE);
} else {
ensureDir(FUSEKI_BASE);
}
// Ensure FUSEKI_BASE has the assumed directories.
dirTemplates = writeableDirectory(FUSEKI_BASE, templatesNameBase);
dirDatabases = writeableDirectory(FUSEKI_BASE, databasesLocationBase);
dirBackups = writeableDirectory(FUSEKI_BASE, backupDirNameBase);
dirConfiguration = writeableDirectory(FUSEKI_BASE, configDirNameBase);
dirLogs = writeableDirectory(FUSEKI_BASE, logsNameBase);
dirSystemDatabase = writeableDirectory(FUSEKI_BASE, systemDatabaseNameBase);
dirFileArea = writeableDirectory(FUSEKI_BASE, systemFileAreaBase);
if (Files.isRegularFile(FUSEKI_BASE))
throw new FusekiConfigException("FUSEKI_BASE exists but is a file");
// Copy missing files into FUSEKI_BASE
copyFileIfMissing(null, DFT_SHIRO_INI, FUSEKI_BASE);
copyFileIfMissing(null, DFT_CONFIG, FUSEKI_BASE);
for (String n : Template.templateNames) {
copyFileIfMissing(null, n, FUSEKI_BASE);
}
serverInitialized = true;
} catch (RuntimeException ex) {
Fuseki.serverLog.error("Exception in server initialization", ex);
throw ex;
}
}
use of org.apache.jena.fuseki.FusekiConfigException in project jena by apache.
the class FusekiServer method copyFileIfMissing.
/** Copy a file from src to dst under name fn.
* If src is null, try as a classpath resource
* @param src Source directory, or null meaning use java resource.
* @param fn File name, a relative path.
* @param dst Destination directory.
*
*/
private static void copyFileIfMissing(Path src, String fn, Path dst) {
Path dstFile = dst.resolve(fn);
if (Files.exists(dstFile))
return;
// fn may be a path.
if (src != null) {
try {
Files.copy(src.resolve(fn), dstFile, StandardCopyOption.COPY_ATTRIBUTES);
} catch (IOException e) {
IO.exception("Failed to copy file " + src, e);
e.printStackTrace();
}
} else {
try {
// Get from the file from area "org/apache/jena/fuseki/server" (our package)
URL url = FusekiServer.class.getResource(fn);
if (url == null)
throw new FusekiConfigException("Field to find resource '" + fn + "'");
InputStream in = url.openStream();
Files.copy(in, dstFile);
} catch (IOException e) {
IO.exception("Failed to copy file from resource: " + src, e);
e.printStackTrace();
}
}
}
Aggregations