How to change configuration to Jetty once it is running

Friday, July 4, 2014

I have an embedded Jetty instance running in an application and I want to change the configuration whilst jetty is running. Specifically I want to add SSL but the question goes for configs generally.


Currently I have an SSL Handler that can be called using a special key to enable https:



// HTTPS Configuration
HttpConfiguration https = new HttpConfiguration();
https.setSecureScheme("https");
https.setSecurePort(port);
https.setSendServerVersion(false);
https.setSendXPoweredBy(false);
https.setSendDateHeader(false);
https.addCustomizer(new SecureRequestCustomizer());

SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(SslHandler.class.getResource(
"/keystore.jks").toExternalForm());
sslContextFactory.setKeyStorePassword("######");
sslContextFactory.setKeyManagerPassword("######");

ServerConnector sslConnector = new ServerConnector(server,
new SslConnectionFactory(sslContextFactory, "http/1.1"),
new HttpConnectionFactory(https));
sslConnector.setPort(port);

server.addConnector(sslConnector);


If I use this exact code when starting the server it works perfectly but if I execute this from the handler the https is not enables.


Do I need to somehow flush the server or stop it and start it again to get the changes to take effect?







http://ift.tt/1klIKgq