use of org.apache.nifi.minifi.c2.api.properties.C2Properties in project nifi-minifi by apache.
the class JettyServer method main.
public static void main(String[] args) throws Exception {
C2Properties properties = C2Properties.getInstance();
final HandlerCollection handlers = new HandlerCollection();
for (Path path : Files.list(Paths.get(C2_SERVER_HOME, "webapps")).collect(Collectors.toList())) {
handlers.addHandler(loadWar(path.toFile(), "/c2", JettyServer.class.getClassLoader()));
}
Server server;
int port = Integer.parseInt(properties.getProperty("minifi.c2.server.port", "10080"));
if (properties.isSecure()) {
SslContextFactory sslContextFactory = properties.getSslContextFactory();
HttpConfiguration config = new HttpConfiguration();
config.setSecureScheme("https");
config.setSecurePort(port);
config.addCustomizer(new SecureRequestCustomizer());
server = new Server();
ServerConnector serverConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(config));
serverConnector.setPort(port);
server.addConnector(serverConnector);
} else {
server = new Server(port);
}
server.setHandler(handlers);
server.start();
// ensure everything started successfully
for (Handler handler : server.getChildHandlers()) {
// see if the handler is a web app
if (handler instanceof WebAppContext) {
WebAppContext context = (WebAppContext) handler;
// cause it to be unavailable
if (context.getUnavailableException() != null) {
System.err.println("Failed to start web server: " + context.getUnavailableException().getMessage());
System.err.println("Shutting down...");
logger.warn("Failed to start web server... shutting down.", context.getUnavailableException());
server.stop();
System.exit(1);
}
}
}
server.dumpStdErr();
server.join();
}
Aggregations