Search in sources :

Example 1 with OverlayedNinjaProperties

use of ninja.utils.OverlayedNinjaProperties in project ninja by ninjaframework.

the class AbstractStandalone method configure.

@Override
public final T configure() throws Exception {
    checkNotConfigured();
    // create ninja properties & overlayed view
    this.ninjaProperties = new NinjaPropertiesImpl(this.ninjaMode, this.externalConfigurationPath);
    this.overlayedNinjaProperties = new OverlayedNinjaProperties(this.ninjaProperties);
    // current value or system property or conf/application.conf or default value
    host(overlayedNinjaProperties.get(KEY_NINJA_HOST, this.host, DEFAULT_HOST));
    port(overlayedNinjaProperties.getInteger(KEY_NINJA_PORT, this.port, DEFAULT_PORT));
    contextPath(overlayedNinjaProperties.get(KEY_NINJA_CONTEXT_PATH, this.contextPath, DEFAULT_CONTEXT_PATH));
    idleTimeout(overlayedNinjaProperties.getLong(KEY_NINJA_IDLE_TIMEOUT, this.idleTimeout, DEFAULT_IDLE_TIMEOUT));
    sslPort(overlayedNinjaProperties.getInteger(KEY_NINJA_SSL_PORT, this.sslPort, DEFAULT_SSL_PORT));
    // defaults below (with self-signed cert) only valid in dev & test modes
    sslKeystoreUri(overlayedNinjaProperties.getURI(KEY_NINJA_SSL_KEYSTORE_URI, this.sslKeystoreUri, (this.ninjaMode == NinjaMode.prod ? null : new URI(DEFAULT_DEV_NINJA_SSL_KEYSTORE_URI))));
    sslKeystorePassword(overlayedNinjaProperties.get(KEY_NINJA_SSL_KEYSTORE_PASSWORD, this.sslKeystorePassword, (this.ninjaMode == NinjaMode.prod ? null : DEFAULT_DEV_NINJA_SSL_KEYSTORE_PASSWORD)));
    sslTruststoreUri(overlayedNinjaProperties.getURI(KEY_NINJA_SSL_TRUSTSTORE_URI, this.sslTruststoreUri, (this.ninjaMode == NinjaMode.prod ? null : new URI(DEFAULT_DEV_NINJA_SSL_TRUSTSTORE_URI))));
    sslTruststorePassword(overlayedNinjaProperties.get(KEY_NINJA_SSL_TRUSTSTORE_PASSWORD, this.sslTruststorePassword, (this.ninjaMode == NinjaMode.prod ? null : DEFAULT_DEV_NINJA_SSL_TRUSTSTORE_PASSWORD)));
    // assign random ports if needed
    if (getPort() == null || getPort() == 0) {
        port(StandaloneHelper.findAvailablePort(8000, 9000));
    }
    if (getSslPort() == null || getSslPort() == 0) {
        sslPort(StandaloneHelper.findAvailablePort(9001, 9999));
    }
    doConfigure();
    this.configured = true;
    // build configured urls
    this.serverUrls = createServerUrls();
    this.baseUrls = createBaseUrls();
    // is there at least one url?
    if (this.serverUrls == null || this.serverUrls.isEmpty()) {
        throw new IllegalStateException("All server ports were disabled." + " Check the 'ninja.port' property and possibly others depending your standalone.");
    }
    // save generated server name as ninja property if its not yet set
    String serverName = this.ninjaProperties.get(NinjaConstant.serverName);
    if (StringUtils.isEmpty(serverName)) {
        // grab the first one
        this.ninjaProperties.setProperty(NinjaConstant.serverName, getServerUrls().get(0));
    }
    return (T) this;
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) OverlayedNinjaProperties(ninja.utils.OverlayedNinjaProperties) URI(java.net.URI)

Aggregations

URI (java.net.URI)1 NinjaPropertiesImpl (ninja.utils.NinjaPropertiesImpl)1 OverlayedNinjaProperties (ninja.utils.OverlayedNinjaProperties)1