@Override public String getWithDefault(String key, String defaultValue) { String value = get(key); if (value != null) { return value; } else { return defaultValue; } }
@Override public Boolean getBooleanWithDefault(String key, Boolean defaultValue) { Boolean value = getBoolean(key); if (value != null) { return value; } else { return defaultValue; } }
@Override public Integer getIntegerWithDefault(String key, Integer defaultValue) { Integer value = getInteger(key); if (value != null) { return value; } else { return defaultValue; } }
@Before public final void initialize() { NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(ninjaMode); injector = Guice.createInjector(new JpaModule(ninjaProperties)); jpaInitializer = injector.getInstance(JpaInitializer.class); jpaInitializer.start(); }
private Bootstrap createNinjaBootstrap( NinjaPropertiesImpl ninjaProperties, String contextPath) { // we set the contextpath. ninjaProperties.setContextPath(contextPath); ninjaBootstrap = new NinjaServletBootstrap(ninjaProperties); // if websocket container present then enable jsr-356 websockets webSocketModule.ifPresent(module -> { ninjaBootstrap.addModule(module); }); ninjaBootstrap.boot(); return ninjaBootstrap; }
@Override protected void doPostConfigure() throws Exception { // 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)); } }
@Override public void configure() { System.setProperty("file.encoding", "utf-8"); // Lifecycle support install(LifecycleSupport.getModule()); // Routing Multibinder.newSetBinder(binder(), ParamParser.class); bind(RouteBuilder.class).to(RouteBuilderImpl.class); bind(Router.class).to(RouterImpl.class).in(Singleton.class); // Logging bind(Logger.class).toProvider(LoggerProvider.class); // Bind the configuration into Guice ninjaProperties.bindProperties(binder()); bind(NinjaProperties.class).toInstance(ninjaProperties); }
isProd(), new File("").getAbsolutePath(), defaultConfiguration,
/** * Start the server and load the routes. */ public void startServer(NinjaMode ninjaMode) { if (ninjaMode == null) { NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl( NinjaModeHelper.determineModeFromSystemPropertiesOrProdIfNotSet()); ninjaBootup = new Bootstrap( ninjaProperties); } else { // in this case servletContext can be null NinjaPropertiesImpl ninjaProperties = new NinjaPropertiesImpl(ninjaMode); ninjaBootup = new Bootstrap(ninjaProperties); } ninjaBootup.boot(); router = ninjaBootup.getInjector().getInstance(Router.class); }
@Override public void doConfigure() throws Exception { // apply properties to settings this.settings.apply(overlayedNinjaProperties); // pass along context (this mirrors what ninja-servlet does) this.ninjaProperties.setContextPath(getContextPath()); // create new bootstrap to kickoff ninja this.ninjaUndertowBootstrap = new NinjaUndertowBootstrap(ninjaProperties); // create chain of undertow handlers this.undertowHandler = createHttpHandler(); this.undertow = createUndertow(); }
= new NinjaPropertiesImpl( NinjaModeHelper.determineModeFromSystemPropertiesOrProdIfNotSet());
@Override public String getOrDie(String key) { String value = get(key); if (value == null) { logger.error(String.format(ERROR_KEY_NOT_FOUND, key)); throw new RuntimeException(String.format(ERROR_KEY_NOT_FOUND, key)); } else { return value; } }
@Override public Boolean getBooleanOrDie(String key) { Boolean value = getBoolean(key); if (value == null) { logger.error(String.format(ERROR_KEY_NOT_FOUND, key)); throw new RuntimeException(String.format(ERROR_KEY_NOT_FOUND, key)); } else { return value; } }
@Override public Integer getIntegerOrDie(String key) { Integer value = getInteger(key); if (value == null) { logger.error(String.format(ERROR_KEY_NOT_FOUND, key)); throw new RuntimeException(String.format(ERROR_KEY_NOT_FOUND, key)); } else { return value; } }
@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 Bootstrap(NinjaPropertiesImpl ninjaProperties) { Preconditions.checkNotNull(ninjaProperties); this.ninjaProperties = ninjaProperties; this.modulesToLoad = new ArrayList<>(); // custom base package for application modules (e.g. com.example.conf.Routes) this.applicationModulesBasePackage = Optional.ofNullable(ninjaProperties.get( NinjaConstant.APPLICATION_MODULES_BASE_PACKAGE)); this.ninjaBaseDirectoryResolver = new NinjaBaseDirectoryResolver(ninjaProperties); }