Configuration

Pierre PINON edited this page Dec 7, 2017 · 37 revisions

Usage

You can configure Jetty Bootstrap using System Properties, a configuration object or both.

The library provides two configuration class to ease Jetty configuration :

  • JettyConfiguration class is the simple implementation of IJettyConfiguration interface and does not support Java System Properties to lookup for configuration values, it has default values and provide necessary getters and setters for each of them.

  • PropertiesJettyConfiguration class extends JettyConfiguration and provide System Properties support. It first loads properties found on the system and then you are free to override these values using the class setters as you would do with JettyConfiguration class.

By default, when no instance of IJettyConfiguration interface is passed by argument to JettyBootstrap constructor, Java System Properties applies since PropertiesJettyConfiguration is used internally.

Sample

  • Java System Properties usage

Simply instantiate Jetty Bootstrap using the empty constructor as follow :

JettyBootstrap jettyBootstrap = new JettyBootstrap()

Set a property on the command line as follow :

java -Dport=9999 -jar ...

or by code from your application :

System.setProperty("port", "9999");
  • JettyConfiguration class usage :

First create a new instance of JettyConfiguration, set the required settings using appropriate setter(s) and pass the configuration object to the JettyBootstrap constructor.

JettyConfiguration jettyConfiguration = new JettyConfiguration();
jettyConfiguration.setPort(9999);
JettyBootstrap jettyBootstrap = new JettyBootstrap(jettyConfiguration);

Properties

autoJoinOnStart

Blocks until the thread pool is stopped

Default : true

e.g.

jettyConfiguration.setAutoJoinOnStart(true);

System.setProperty("autoJoinOnStart", "true");

maxThreads

Set the maximum number of threads

Default : 128

e.g.

jettyConfiguration.setMaxThreads(128);

System.setProperty("maxThreads", "128");

stopAtShutdown

Add Shutdown Hook to Runtime for stop server

Default : true

e.g.

jettyConfiguration.setStopAtShutdown(true);

System.setProperty("stopAtShutdown", "true");

stopTimeout

Shutdown Timeout

Default : 5000

e.g.

jettyConfiguration.setStopTimeout(5000);

System.setProperty("stopTimeout", "5000");

idleTimeout

Idle Timeout

Default : 30000

e.g.

jettyConfiguration.setIdleTimeout(30000);

System.setProperty("idleTimeout", "30000");

blockingTimeout [Since v1.0.13]

Blocking Timeout

Default : -1

e.g.

jettyConfiguration.setBlockingTimeout(-1);

System.setProperty("blockingTimeout", "-1");

host

Listen Host

Default : "0.0.0.0"

e.g.

jettyConfiguration.setHost("0.0.0.0");

System.setProperty("host", "0.0.0.0");

port

Http Port

Default : 8080

e.g.

jettyConfiguration.setPort(8080);

System.setProperty("port", "8080");

sslPort

Https Port

Default : 8443

e.g.

jettyConfiguration.setSslPort(8443);

System.setProperty("sslPort", "8443");

jettyConnectors

Connectors

Values

  • JettyConnector.HTTP : Connector on Property port
  • JettyConnector.HTTPS : SSL connector on Property sslPort

Default : JettyConnector.HTTP

e.g.

jettyConfiguration.setJettyConnectors(JettyConnector.HTTP);

jettyConfiguration.setJettyConnectors(JettyConnector.HTTPS);

jettyConfiguration.setJettyConnectors(JettyConnector.HTTP, JettyConnector.HTTPS);

System.setProperty("connectors", "HTTP");

System.setProperty("connectors", "HTTPS");

System.setProperty("connectors", "HTTP,HTTPS");

redirectWebAppsOnHttpsConnector

Redirect WebApps on HTTPS Connector

To use this option, you need to set HTTP and HTTPS Connectors

Default : false

e.g.

jettyConfiguration.setRedirectWebAppsOnHttpsConnector(false);

System.setProperty("redirectWebAppsOnHttpsConnector", "false");

sslPrivateKeyFormat [Since v1.0.7]

SSL private key format, used for HTTPS support.

Default : JettySslFileFormat.PKCS8

e.g.

jettyConfiguration.setSslPrivateKeyFormat(JettySslFileFormat.PKCS8);

System.setProperty("sslPrivateKeyFormat", "pkcs8");

sslPrivateKeyPath [Since v1.0.5]

SSL private key path, used for HTTPS support.

Default : null

e.g.

jettyConfiguration.setSslPrivateKeyPath("/tmp/myApp.key");

System.setProperty("sslPrivateKeyPath", "/tmp/myApp.key");

sslPrivateKeyPassword [Since v1.0.7]

SSL private key password, used for HTTPS support.

Default : null

e.g.

jettyConfiguration.setSslPrivateKeyPassword("mypassword");

System.setProperty("sslPrivateKeyPassword", "mypassword");

sslCertificateFormat [Since v1.0.7]

SSL certificate format, used for HTTPS support.

Default : JettySslFileFormat.PKCS8

e.g.

jettyConfiguration.setSslCertificateFormat(JettySslFileFormat.PKCS8);

System.setProperty("sslCertificateFormat", "pkcs8");

sslCertificatePath [Since v1.0.5]

SSL certificate path, used for HTTPS support.

Default : null

e.g.

jettyConfiguration.setSslCertificatePath("/tmp/myApp.crt");

System.setProperty("sslCertificatePath", "/tmp/myApp.crt");

sslCertificatePassword [Since v1.0.7]

SSL certificate password, used for HTTPS support.

Default : null

e.g.

jettyConfiguration.setSslCertificatePassword("mypassword");

System.setProperty("sslCertificatePassword", "mypassword");

sslKeyStore

KeyStore for SSL

[Since v1.0.6]

Default : null

e.g.

jettyConfiguration.setSslKeyStore(keystore);

sslKeyStorePath

KeyStore Path for SSL

If connector HTTPS is setted and this property is null, a new keystore is automatically generated

[Since v1.0.5]

If path is specified but not exists, create it anyway.

Default : null (tempDirectory/default.keystore)

e.g.

jettyConfiguration.setSslKeyStorePath("/tmp/myApp.keystore");

System.setProperty("sslKeystorePath", "/tmp/myApp.keystore");

sslKeyStoreDomainName [Since v1.0.5]

Keystore domain name for SSL

Default : "unknown"

e.g.

jettyConfiguration.setSslKeystoreDomainName("domain");

System.setProperty("sslKeystoreDomainName", "domain");

sslKeyStoreAlias [Since v1.0.5]

Keystore alias for SSL

Default : "alias"

e.g.

jettyConfiguration.setSslKeystoreAlias("alias");

System.setProperty("sslKeystoreAlias", "alias");

sslKeyStorePassword

KeyStore Password for SSL

Default : "jettybootstrap"

e.g.

jettyConfiguration.setSslKeystorePassword("myPassword");

System.setProperty("sslKeystorePassword", "myPassword");

sslKeyStoreAlgorithm [Since v1.0.5]

Keystore algorithm for SSL

Default : JettyKeystore.ALGORITHM_RSA

e.g.

jettyConfiguration.setSslKeystoreAlgorithm(JettyKeystore.ALGORITHM_RSA);

System.setProperty("sslKeystoreAlgorithm", "RSA");

sslKeyStoreSignatureAlgorithm

Keystore signature algorithm for SSL

Default : JettyKeystore.SIGNATURE_ALGORITHM_SHA256WITHRSA

e.g.

jettyConfiguration.setSslKeystoreSignatureAlgorithm(JettyKeystore.SIGNATURE_ALGORITHM_SHA256WITHRSA);

System.setProperty("sslKeystoreSignatureAlgorithm", "SHA256WithRSAEncryption");

sslKeyStoreRdnOuValue [Since v1.0.5]

Keystore RDN OU Value for SSL

Default : "None"

e.g.

jettyConfiguration.setSslKeystoreRdnOuValue("rndouvalue");

System.setProperty("sslKeystoreRdnOuValue", "rndouvalue");

sslKeyStoreRdnOValue [Since v1.0.5]

Keystore RDN O Value for SSL

Default : "None"

e.g.

jettyConfiguration.setSslKeystoreRdnOValue("rndovalue");

System.setProperty("sslKeystoreRdnOValue", "rndovalue");

dateNotBeforeNumberOfDays [Since v1.0.5]

Keystore number of days before validity for SSL

Default : 30

e.g.

jettyConfiguration.setSslKeystoreDateNotBeforeNumberOfDays(30);

System.setProperty("sslKeystoreDateNotBeforeNumberOfDays", "30");

dateNotAfterNumberOfDays [Since v1.0.5]

Keystore number of days after validity for SSL

Default : 365

e.g.

jettyConfiguration.setSslKeystoreDateNotAfterNumberOfDays(365);

System.setProperty("sslKeystoreDateNotAfterNumberOfDays", "365");

tempDirectory

Runtime Temporary Directory

Values

  • JettyBootstrap.TEMP_DIRECTORY_JARDIR : Temp Directory will be create near jar
  • JettyBootstrap.TEMP_DIRECTORY_SYSTEM : Temp Directory will be create in System Temp Directory
  • Free Value

Default : JettyBootstrap.TEMP_DIRECTORY_JARDIR

e.g.

jettyConfiguration.setTempDirectory("/tmp/myAppTemp");

jettyConfiguration.setTempDirectory(JettyBootstrap.TEMP_DIRECTORY_JARDIR);

jettyConfiguration.setTempDirectory(JettyBootstrap.TEMP_DIRECTORY_SYSTEMP);

System.setProperty("tempDirectory", "/tmp/myAppTemp");

persistAppTempDirectories

Don't delete Temporary WebApp Directories on Start

Default : false

e.g.

jettyConfiguration.setPersistAppTempDirectories(false);

System.setProperty("persistAppTempDirectories", "false");

cleanTempDir

Delete Runtime Temporary Directory on Start

Default : false

e.g.

jettyConfiguration.setCleanTempDir(false);

System.setProperty("cleanTempDir", "false");

parentLoaderPriority

Sets the classloading model for all webapps

Default : true

e.g.

jettyConfiguration.setParentLoaderPriority(true);

System.setProperty("parentLoaderPriority", "true");

throwIfStartupException [Since v1.0.3]

Set whether or not the server should stop when a web application startup fails

Default : true

e.g.

jettyConfiguration.setThrowIfStartupException(true);

System.setProperty("throwIfStartupException", "true");

maxInactiveInterval [Since v1.0.4]

Max period of inactivity, after which the session is invalidated, in seconds

Default : -1

e.g.

jettyConfiguration.setMaxInactiveInterval(-1);

System.setProperty("maxInativeInterval", "-1");

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.