Search in sources :

Example 1 with C2Properties

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();
}
Also used : Path(java.nio.file.Path) SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) Handler(org.eclipse.jetty.server.Handler) C2Properties(org.apache.nifi.minifi.c2.api.properties.C2Properties) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ServerConnector(org.eclipse.jetty.server.ServerConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection)

Aggregations

Path (java.nio.file.Path)1 C2Properties (org.apache.nifi.minifi.c2.api.properties.C2Properties)1 Handler (org.eclipse.jetty.server.Handler)1 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)1 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)1 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)1 Server (org.eclipse.jetty.server.Server)1 ServerConnector (org.eclipse.jetty.server.ServerConnector)1 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)1 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)1 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)1 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)1