Jetty 9嵌入式SSL需要12分钟才能启动

时间:2019-02-08 15:14:43

标签: java jetty embedded-jetty jetty-9

我有一个在Jetty上运行的Spring应用程序。我们最近将正在使用的Jetty版本从6.x升级到了最新的稳定版本9.4.14

在我们开始运行该应用程序的构建版本之前,所有设置似乎都工作良好。引导时,Jetty需要12分钟才能启动服务器!

我的日志:

2019-02-08 14:54:15,917 INFO [ContextHandler] Started o.e.j.w.WebAppContext@1f554b06{RTD2,/web,file:///data/XXX/war/,AVAILABLE}{/data/XXX/war}
2019-02-08 14:54:16,123 INFO [SslContextFactory] x509=X509@33beb1(1,h=[XXX.co.uk],w=[XXX.co.uk]) for SslContextFactory@480f6625[provider=null,keyStore=file:///data/XX/config/keystore2,trustStore=file:///etc/ssl/certs/java/cacerts]
2019-02-08 15:07:08,063 WARN [config] No Client EndPointIdentificationAlgorithm configured for SslContextFactory@480f6625[provider=null,keyStore=file:///data/XX/config/keystore2,trustStore=file:///etc/ssl/certs/java/cacerts]
2019-02-08 15:07:08,101 INFO [AbstractConnector] Started ServerConnector@124e2ad9{SSL,[ssl, http/1.1]}{0.0.0.0:443}
2019-02-08 15:07:08,101 INFO [Server] Started @820820ms

我的入门班:

public class RunJetty {
    public static void main(String[] args) {

        if (args.length < 4) {
            System.out.println("Insufficient arguments supplied");
            usage();
            System.exit(1);
        }

        try {

            int port = getPort(args[0]);
            File configLocation = getContextLocation(args[1]);
            String contextPath = getContextPath(args[2]);
            String scheme = args[3];
            String resourceBase = args(args, 4, "html");

            Server server = new Server();

            ServerConnector sslConnector = null;
            boolean https = scheme.equals("https");
            boolean http = scheme.equals("http");
            boolean both = scheme.equals("both");
            int sslPort = -1;
            if (https || both) {

                HttpConfiguration httpConfig = new HttpConfiguration();
                httpConfig.setSendServerVersion( false );
                httpConfig.addCustomizer(new SecureRequestCustomizer());
                HttpConnectionFactory httpFactory = new HttpConnectionFactory( httpConfig );

                SslContextFactory sslContextFactory = new SslContextFactory();
                sslContextFactory.setKeyStorePath(System.getProperty("jetty.ssl.keystore"));
                sslContextFactory.setKeyStorePassword(System.getProperty("jetty.ssl.keystore.password"));
                sslContextFactory.setKeyManagerPassword(System.getProperty("jetty.ssl.key.password"));
                sslContextFactory.setTrustStorePath(System.getProperty("jetty.ssl.truststore"));
                sslContextFactory.setTrustStorePassword(System.getProperty("jetty.ssl.truststore.password"));

                SslConnectionFactory sslFactory =  new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString());

                sslConnector = new ServerConnector(server,sslFactory,httpFactory);

                sslPort = https ? port : Integer.parseInt(System.getProperty("ssl.port"));
                sslConnector.setPort(sslPort);

            }

            ServerConnector connector = null;

            if (http || both) {

                HttpConfiguration httpConfig = new HttpConfiguration();
                httpConfig.setSendServerVersion( false );
                if (both) {
                    httpConfig.setSecurePort(sslPort);
                }
                HttpConnectionFactory httpFactory = new HttpConnectionFactory( httpConfig );

                connector = new ServerConnector( server,httpFactory );
                connector.setPort(port);
            }

            Connector[] connectors = null;

            if (both) {
                connectors = new Connector[] { connector, sslConnector };
            } else if (http) {
                connectors = new Connector[] { connector };
            } else if (https) {
                connectors = new Connector[] { sslConnector };
            } else {
                throw new IllegalArgumentException("Invalid scheme. Must be 'http', 'https' or 'both'");
            }

            server.setConnectors(connectors);

            HandlerCollection handlers = new HandlerCollection();
            ResourceHandler resourceHandler = new ResourceHandler();
            resourceHandler.setResourceBase(resourceBase);

            ContextHandlerCollection contexts = new ContextHandlerCollection();

            WebAppContext webAppContext = new WebAppContext(configLocation.getAbsolutePath(), contextPath);

            contexts.addHandler(webAppContext);

            RequestLogHandler requestLogHandler = new RequestLogHandler();
            handlers.setHandlers(new Handler[] { contexts, resourceHandler, new DefaultHandler(), requestLogHandler });
            server.setHandler(handlers);

            server.setStopAtShutdown(true);

            try {
                server.start();
                server.join();
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
        catch (IllegalArgumentException e) {
            System.out.println(e.getMessage());
            usage();
            System.exit(-1);
        }
    }

    static String args(String[] args, int index, String defaultValue) {
        if (args.length < index+1) {
            return defaultValue;
        }
        return args[index];
    }

    static String getContextPath(String arg) {
        if (!arg.startsWith("/")) {
            arg = "/" + arg;
        }
        return arg;
    }

    static File getContextLocation(String arg) {
        File file = new File(arg);
        if (!file.exists()) {
            throw new IllegalArgumentException("Invalid context directory: " + file.getAbsolutePath());
        }
        return file;
    }

    static int getPort(String arg) {
        int port = 8080;
        try {
            port = Integer.parseInt(arg);
        }
        catch (NumberFormatException e1) {
            throw new IllegalArgumentException("Invalid port: " + arg);
        }
        return port;
    }


    private static void usage() {
        System.out.println(RunJetty.class.getName() + " [port] [context directory] [path] [http|https|both]");
    }
}

0 个答案:

没有答案