Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* eXist Open Source Native XML Database
* Copyright (C) 2001-2014 The eXist-db Project
* http://exist-db.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package org.exist.jetty;
import java.io.IOException;
import java.io.InputStream;
import java.io.LineNumberReader;
import java.io.Reader;
import java.net.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;
import javax.servlet.Servlet;
import net.jcip.annotations.GuardedBy;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.jetty.server.*;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.HandlerWrapper;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.Jetty;
import org.eclipse.jetty.util.MultiException;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.xml.XmlConfiguration;
import org.exist.SystemProperties;
import org.exist.start.Main;
import org.exist.storage.BrokerPool;
import org.exist.util.ConfigurationHelper;
import org.exist.util.FileUtils;
import org.exist.util.SingleInstanceConfiguration;
import org.exist.validation.XmlLibraryChecker;
import org.exist.xmldb.DatabaseImpl;
import org.exist.xmldb.ShutdownListener;
import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Database;
import static org.exist.util.ThreadUtils.newGlobalThread;
/**
* This class provides a main method to start Jetty with eXist. It registers shutdown
* handlers to cleanly shut down the database and the webserver.
*
* @author wolf
*/
public class JettyStart extends Observable implements LifeCycle.Listener {
public static final String JETTY_HOME_PROP = "jetty.home";
public static final String JETTY_BASE_PROP = "jetty.base";
private static final String JETTY_PROPETIES_FILENAME = "jetty.properties";
private static final Logger logger = LogManager.getLogger(JettyStart.class);
public final static String SIGNAL_STARTING = "jetty starting";
public final static String SIGNAL_STARTED = "jetty started";
public final static String SIGNAL_ERROR = "error";
private final static int STATUS_STARTING = 0;
private final static int STATUS_STARTED = 1;
private final static int STATUS_STOPPING = 2;
private final static int STATUS_STOPPED = 3;
@GuardedBy("this") private int status = STATUS_STOPPED;
@GuardedBy("this") private Optional shutdownHookThread = Optional.empty();
@GuardedBy("this") private int primaryPort = 8080;
public static void main(final String[] args) {
final JettyStart start = new JettyStart();
start.run(args, null);
}
public JettyStart() {
// Additional checks XML libs @@@@
XmlLibraryChecker.check();
}
public synchronized void run() {
run(true);
}
public synchronized void run(final boolean standalone) {
final String jettyProperty = Optional.ofNullable(System.getProperty(JETTY_HOME_PROP))
.orElseGet(() -> {
final Optional home = ConfigurationHelper.getExistHome();
final Path jettyHome = FileUtils.resolve(home, "tools").resolve("jetty");
final String jettyPath = jettyHome.toAbsolutePath().toString();
System.setProperty(JETTY_HOME_PROP, jettyPath);
return jettyPath;
});
System.setProperty("org.eclipse.jetty.util.log.class?", "org.eclipse.jetty.util.log.Slf4jLog");
final Path jettyConfig;
if (standalone) {
jettyConfig = Paths.get(jettyProperty).resolve("etc").resolve(Main.STANDALONE_ENABLED_JETTY_CONFIGS);
} else {
jettyConfig = Paths.get(jettyProperty).resolve("etc").resolve(Main.STANDARD_ENABLED_JETTY_CONFIGS);
}
run(new String[] { jettyConfig.toAbsolutePath().toString() }, null);
}
public synchronized void run(final String[] args, final Observer observer) {
if (args.length == 0) {
logger.error("No configuration file specified!");
return;
}
Path jettyConfig = Paths.get(args[0]);
boolean configFromClasspath = false;
if (Files.notExists(jettyConfig)) {
logger.warn("Configuration file: {} does not exist!", jettyConfig.toAbsolutePath().toString());
final String jettyConfigFileName = FileUtils.fileName(jettyConfig.getFileName());
logger.warn("Fallback... searching for configuration file on classpath: {}.etc/{}", getClass().getPackage().getName(), jettyConfigFileName);
final URL jettyConfigUrl = getClass().getResource("etc/" + jettyConfigFileName);
if (jettyConfigUrl != null) {
try {
jettyConfig = Paths.get(jettyConfigUrl.toURI());
configFromClasspath = true;
} catch (final URISyntaxException e) {
logger.error("Unable to retrieve configuration file from classpath: {}", e.getMessage(), e);
return;
}
} else {
logger.error("Unable to find configuration file on classpath!");
return;
}
}
final Map configProperties;
try {
configProperties = getConfigProperties(jettyConfig.getParent());
// modify JETTY_HOME and JETTY_BASE properties when running with classpath config
if (configFromClasspath) {
final String jettyClasspathHome = jettyConfig.getParent().getParent().toAbsolutePath().toString();
System.setProperty(JETTY_HOME_PROP, jettyClasspathHome);
configProperties.put(JETTY_HOME_PROP, jettyClasspathHome);
configProperties.put(JETTY_BASE_PROP, jettyClasspathHome);
}
if (observer != null) {
addObserver(observer);
}
logger.info("Running with Java {} [{} ({}) in {}]",
System.getProperty("java.version", "(unknown java.version)"),
System.getProperty("java.vendor", "(unknown java.vendor)"),
System.getProperty("java.vm.name", "(unknown java.vm.name)"),
System.getProperty("java.home", "(unknown java.home)")
);
logger.info("Running as user '{}'", System.getProperty("user.name", "(unknown user.name)"));
logger.info("[eXist Home : {}]", System.getProperty("exist.home", "unknown"));
logger.info("[eXist Version : {}]", SystemProperties.getInstance().getSystemProperty("product-version", "unknown"));
logger.info("[eXist Build : {}]", SystemProperties.getInstance().getSystemProperty("product-build", "unknown"));
logger.info("[Git commit : {}]", SystemProperties.getInstance().getSystemProperty("git-commit", "unknown"));
logger.info("[Operating System : {} {} {}]", System.getProperty("os.name"), System.getProperty("os.version"), System.getProperty("os.arch"));
logger.info("[log4j.configurationFile : {}]", System.getProperty("log4j.configurationFile"));
logger.info("[jetty Version: {}]", Jetty.VERSION);
logger.info("[{} : {}]", JETTY_HOME_PROP, configProperties.get(JETTY_HOME_PROP));
logger.info("[{} : {}]", JETTY_BASE_PROP, configProperties.get(JETTY_BASE_PROP));
logger.info("[jetty configuration : {}]", jettyConfig.toAbsolutePath().toString());
// configure the database instance
SingleInstanceConfiguration config;
if (args.length == 2) {
config = new SingleInstanceConfiguration(args[1]);
} else {
config = new SingleInstanceConfiguration();
}
logger.info("Configuring eXist from {}",
config.getConfigFilePath()
.map(Path::normalize).map(Path::toAbsolutePath).map(Path::toString)
.orElse(""));
BrokerPool.configure(1, 5, config, Optional.ofNullable(observer));
// register the XMLDB driver
final Database xmldb = new DatabaseImpl();
xmldb.setProperty("create-database", "false");
DatabaseManager.registerDatabase(xmldb);
} catch (final Exception e) {
logger.error("configuration error: " + e.getMessage(), e);
e.printStackTrace();
return;
}
try {
// load jetty configurations
final List configFiles = getEnabledConfigFiles(jettyConfig);
final List