public Long getLong(String key, Long currentValue, Long defaultValue) { String value = null; try { value = get(key, safeToString(currentValue), safeToString(defaultValue)); if (StringUtils.isEmpty(value)) { return null; } return Long.valueOf(value); } catch (Exception e) { throw new IllegalArgumentException("Unable to convert property '" + key + "' with value '" + value + "' to a Long", e); } }
@Override protected void doPreConfigure() throws Exception { // current value or system property or conf/application.conf or default value host(overlayedNinjaProperties.get(Standalone.KEY_NINJA_HOST, this.host, Standalone.DEFAULT_HOST)); port(overlayedNinjaProperties.getInteger(Standalone.KEY_NINJA_PORT, this.port, Standalone.DEFAULT_PORT)); contextPath(overlayedNinjaProperties.get(Standalone.KEY_NINJA_CONTEXT_PATH, this.contextPath, Standalone.DEFAULT_CONTEXT_PATH)); idleTimeout(overlayedNinjaProperties.getLong(Standalone.KEY_NINJA_IDLE_TIMEOUT, this.idleTimeout, Standalone.DEFAULT_IDLE_TIMEOUT)); sslPort(overlayedNinjaProperties.getInteger(Standalone.KEY_NINJA_SSL_PORT, this.sslPort, Standalone.DEFAULT_SSL_PORT)); // defaults below (with self-signed cert) only valid in dev & test modes sslKeystoreUri(overlayedNinjaProperties.getURI(Standalone.KEY_NINJA_SSL_KEYSTORE_URI, this.sslKeystoreUri, this.ninjaMode == NinjaMode.prod ? null : new URI(Standalone.DEFAULT_DEV_NINJA_SSL_KEYSTORE_URI))); sslKeystorePassword(overlayedNinjaProperties.get(Standalone.KEY_NINJA_SSL_KEYSTORE_PASSWORD, this.sslKeystorePassword, this.ninjaMode == NinjaMode.prod ? null : Standalone.DEFAULT_DEV_NINJA_SSL_KEYSTORE_PASSWORD)); sslTruststoreUri(overlayedNinjaProperties.getURI(Standalone.KEY_NINJA_SSL_TRUSTSTORE_URI, this.sslTruststoreUri, this.ninjaMode == NinjaMode.prod ? null : new URI(Standalone.DEFAULT_DEV_NINJA_SSL_TRUSTSTORE_URI))); sslTruststorePassword(overlayedNinjaProperties.get(Standalone.KEY_NINJA_SSL_TRUSTSTORE_PASSWORD, this.sslTruststorePassword, this.ninjaMode == NinjaMode.prod ? null : Standalone.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)); } }
@Override protected void doConfigure() throws Exception { jettyConfiguration(overlayedNinjaProperties.get( KEY_NINJA_JETTY_CONFIGURATION, this.jettyConfiguration, DEFAULT_JETTY_CONFIGURATION));
@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); this.doPreConfigure(); this.doConfigure(); this.configured = true; this.doPostConfigure(); return (T) this; }
public void apply(OverlayedNinjaProperties overlayedNinjaProperties) { // apply defaults in order of precedence this.tracing = overlayedNinjaProperties.getBoolean( TRACING, this.tracing, Boolean.FALSE); this.http2 = overlayedNinjaProperties.getBoolean( HTTP2, this.http2, Boolean.FALSE); }
public Integer getInteger(String key, Integer currentValue, Integer defaultValue) { String value = null; try { value = get(key, safeToString(currentValue), safeToString(defaultValue)); if (StringUtils.isEmpty(value)) { return null; } return Integer.valueOf(value); } catch (Exception e) { throw new IllegalArgumentException("Unable to convert property '" + key + "' with value '" + value + "' to an Integer", e); } }
public URI getURI(String key, URI currentValue, URI defaultValue) { String value = null; try { value = get(key, safeToString(currentValue), safeToString(defaultValue)); if (StringUtils.isEmpty(value)) { return null; } return new URI(value); } catch (Exception e) { throw new IllegalArgumentException("Unable to convert property '" + key + "' with value '" + value + "' to a URI", e); } }
public Boolean getBoolean(String key, Boolean currentValue, Boolean defaultValue) { String value = get(key, safeToString(currentValue), safeToString(defaultValue)); if (StringUtils.isEmpty(value)) { return null; } if ("true".equalsIgnoreCase(value)) { return Boolean.TRUE; } else if ("false".equalsIgnoreCase(value)) { return Boolean.FALSE; } else { throw new IllegalArgumentException("Unable to convert property '" + key + "' with value '" + value + "' to a Boolean"); } }