Search in sources :

Example 26 with NinjaPropertiesImpl

use of ninja.utils.NinjaPropertiesImpl 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)

Example 27 with NinjaPropertiesImpl

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

the class ApplicationControllerTest method testMissingKeyedRoute.

@Test
public void testMissingKeyedRoute() {
    NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(NinjaMode.test);
    Provider<RouteBuilderImpl> routeBuilderImplProvider = Mockito.mock(Provider.class);
    when(routeBuilderImplProvider.get()).thenAnswer((invocation) -> new RouteBuilderImpl(ninjaProperties, ninjaBaseDirectoryResolver));
    RouterImpl router = new RouterImpl(injector, ninjaProperties, routeBuilderImplProvider);
    Routes routes = new Routes(ninjaProperties);
    routes.init(router);
    router.compileRoutes();
    String route = router.getReverseRoute(ApplicationController.class, "testKeyedRoute");
    Assert.assertNull(route);
}
Also used : NinjaPropertiesImpl(ninja.utils.NinjaPropertiesImpl) RouteBuilderImpl(ninja.RouteBuilderImpl) RouterImpl(ninja.RouterImpl) Routes(testapplication.conf.Routes) Test(org.junit.Test)

Aggregations

NinjaPropertiesImpl (ninja.utils.NinjaPropertiesImpl)27 Test (org.junit.Test)19 Injector (com.google.inject.Injector)13 BaseAndClassicModules (ninja.BaseAndClassicModules)9 Before (org.junit.Before)4 Bootstrap (ninja.Bootstrap)3 Route (ninja.Route)3 RouteBuilderImpl (ninja.RouteBuilderImpl)3 Router (ninja.Router)3 RouterImpl (ninja.RouterImpl)3 Routes (testapplication.conf.Routes)3 AbstractModule (com.google.inject.AbstractModule)2 LangImpl (ninja.i18n.LangImpl)2 ParamParser (ninja.params.ParamParser)2 Multibinder (com.google.inject.multibindings.Multibinder)1 URI (java.net.URI)1 Context (ninja.Context)1 Cache (ninja.cache.Cache)1 JpaInitializer (ninja.jpa.JpaInitializer)1 JpaModule (ninja.jpa.JpaModule)1