DeploymentManagerFactory(XnioWorker xnioWorker, Coffig configuration, Map<String, String> initParameters) { this.xnioWorker = xnioWorker; this.undertowConfig = configuration.get(UndertowConfig.class); this.applicationConfig = configuration.get(ApplicationConfig.class); this.serverConfig = configuration.get(WebConfig.ServerConfig.class); this.initParameters = initParameters; }
@SuppressWarnings("unchecked") public <T> T get(Class<T> configurationClass, String... path) { return (T) get((Type) configurationClass, path); }
ApplicationImpl(Coffig coffig, Map<String, String> kernelParameters, String[] arguments) { this.coffig = coffig; this.applicationConfig = coffig.get(ApplicationConfig.class); this.kernelParameters = kernelParameters; this.arguments = arguments; this.storageDirectory = configureLocalStorage(applicationConfig); }
@Inject public InternalErrorExceptionMapper(Application application) { this.exceptionMappingConfig = application.getConfiguration().get(RestConfig.ExceptionMappingConfig.class); }
protected <T> T getConfiguration(Class<T> configClass, String... path) { return getConfiguration().get(configClass, path); } }
@Override public String pluginPackageRoot() { ApplicationConfig applicationConfig = coffig.get(ApplicationConfig.class); if (applicationConfig.getBasePackages().isEmpty() && applicationConfig.isPackageScanWarning()) { LOGGER.warn("No base package configured, only classes in 'org.seedstack.*' packages will be scanned"); } Set<String> basePackages = new HashSet<>(applicationConfig.getBasePackages()); basePackages.add(CONFIGURATION_PACKAGE); return String.join(",", basePackages); }
@Inject public I18nConfigurationHandler(Application application, LocaleService localeService) { I18nConfig i18nConfig = application.getConfiguration().get(I18nConfig.class); List<String> additionalLocales = i18nConfig.getAdditionalLocales(); supportedLocales = sortLanguages( W20_BUILTIN_LOCALES, additionalLocales.toArray(new String[additionalLocales.size()]) ); localeMatcher = new LocaleMatcher(LocalePriorityList.add(Joiner.on(',').join(supportedLocales)).build()); this.localeService = localeService; }
public static void refresh() { if (initialized && !disposed) { Seed instance = getInstance(); instance.configuration.refresh(); instance.logManager.refresh(instance.configuration.get(LoggingConfig.class)); instance.proxyManager.refresh(instance.configuration.get(ProxyConfig.class)); // Trigger afterRefresh() in custom initializers for (SeedInitializer seedInitializer : seedInitializers) { try { seedInitializer.afterRefresh(); } catch (Exception e) { throw SeedException.wrap(e, CoreErrorCode.ERROR_IN_INITIALIZER) .put("initializerClass", seedInitializer.getClass().getName()); } } } }
@Inject WebResourcesResolverImpl(final Application application, @Assisted ServletContext servletContext) { WebConfig.StaticResourcesConfig staticResourcesConfig = application.getConfiguration().get( WebConfig.class).staticResources(); this.servletContext = servletContext; this.classLoader = ClassLoaders.findMostCompleteClassLoader(WebResourcesResolverImpl.class); this.serveMinifiedResources = staticResourcesConfig.isMinificationEnabled(); this.serveGzippedResources = staticResourcesConfig.isGzipEnabled(); this.onTheFlyGzipping = staticResourcesConfig.isOnTheFlyGzipEnabled(); }
@Override public TransactionMetadata resolve(MethodInvocation methodInvocation, TransactionMetadata defaults) { Optional<Jdbc> jdbcOptional = JdbcResolver.INSTANCE.apply(methodInvocation.getMethod()); if (jdbcOptional.isPresent() || JdbcTransactionHandler.class.equals(defaults.getHandler())) { TransactionMetadata result = new TransactionMetadata(); result.setHandler(JdbcTransactionHandler.class); result.setExceptionHandler(JdbcExceptionHandler.class); if (jdbcOptional.isPresent() && !Strings.isNullOrEmpty(jdbcOptional.get().value())) { result.setResource(jdbcOptional.get().value()); } else { String defaultDatasource = application.getConfiguration().get(JdbcConfig.class).getDefaultDataSource(); if (!Strings.isNullOrEmpty(defaultDatasource)) { result.setResource(defaultDatasource); } else { throw SeedException.createNew(JdbcErrorCode.NO_DATASOURCE_SPECIFIED_FOR_TRANSACTION) .put("method", methodInvocation.getMethod().toString()); } } return result; } return null; } }
@Override @SuppressFBWarnings(value = "DM_EXIT", justification = "CliLauncher must be able to return a code to the system") public void launch(String[] args, Map<String, String> kernelParameters) throws Exception { CliConfig cliConfig = Seed.baseConfiguration().get(CliConfig.class); String cliCommand; CliContext cliContext; if (cliConfig.hasDefaultCommand()) { cliCommand = cliConfig.getDefaultCommand(); cliContext = new CliContextInternal(args); } else { if (args == null || args.length == 0 || args[0].isEmpty()) { throw SeedException.createNew(CliErrorCode.NO_COMMAND_SPECIFIED); } cliCommand = args[0]; cliContext = new CliContextInternal(args, 1); } int statusCode = execute(cliCommand, cliContext, kernelParameters); LOGGER.info("CLI command finished with status code {}", statusCode); System.exit(statusCode); }
@Override public TransactionMetadata resolve(MethodInvocation methodInvocation, TransactionMetadata defaults) { Optional<JpaUnit> jpaUnitOptional = JpaUnitResolver.INSTANCE .apply(methodInvocation.getMethod()); if (jpaUnitOptional.isPresent() || JpaTransactionHandler.class.equals(defaults.getHandler())) { TransactionMetadata result = new TransactionMetadata(); result.setHandler(JpaTransactionHandler.class); result.setExceptionHandler(JpaExceptionHandler.class); if (jpaUnitOptional.isPresent() && !Strings.isNullOrEmpty(jpaUnitOptional.get().value())) { result.setResource(jpaUnitOptional.get().value()); } else { String defaultUnit = application.getConfiguration().get(JpaConfig.class).getDefaultUnit(); if (!Strings.isNullOrEmpty(defaultUnit)) { result.setResource(defaultUnit); } else { throw SeedException.createNew(JpaErrorCode.NO_JPA_UNIT_SPECIFIED_FOR_TRANSACTION) .put("method", methodInvocation.getMethod().toString()); } } return result; } return null; } }
@Override public void initialize(Coffig coffig) { CryptoConfig cryptoConfig = coffig.get(CryptoConfig.class); masterKeyStoreConfig = cryptoConfig.masterKeyStore(); if (masterKeyStoreConfig != null) { try { KeyStore keyStore = new KeyStoreLoader().load(CryptoConfig.MASTER_KEY_STORE_NAME, masterKeyStoreConfig); encryptionServiceFactory = new EncryptionServiceFactory(cryptoConfig, keyStore); } catch (Exception e) { storedException = e; } } }
@Override public void init(FilterConfig config) throws ServletException { Injector injector = ServletContextUtils.getInjector(config.getServletContext()); WebConfig.StaticResourcesConfig staticResourcesConfig = injector.getInstance( Application.class).getConfiguration().get(WebConfig.class).staticResources(); this.bufferSize = staticResourcesConfig.getBufferSize(); // round the time to nearest second for proper comparison with If-Modified-Since header this.servletInitTime = System.currentTimeMillis() / 1000L * 1000L; WebConfig.StaticResourcesConfig.CacheConfig cacheConfig = staticResourcesConfig.cacheConfig(); this.resourceInfoCache = CacheBuilder.newBuilder() .maximumSize(cacheConfig.getMaxSize()) .concurrencyLevel(cacheConfig.getConcurrencyLevel()) .initialCapacity(cacheConfig.getInitialSize()) .build(new CacheLoader<ResourceRequest, Optional<ResourceInfo>>() { @Override public Optional<ResourceInfo> load(ResourceRequest key) { return java.util.Optional.ofNullable(webResourceResolver.resolveResourceInfo(key)); } }); this.webResourceResolver = injector.getInstance(WebResourceResolverFactory.class).createWebResourceResolver( config.getServletContext()); }
@Override protected MongoClient doCreateClient(String clientName, MongoDbConfig.ClientConfig clientConfig, Coffig coffig) { AllOptions allOptions = coffig.get(AllOptions.class, String.format("mongoDb.clients.%s", clientName)); if (clientConfig.isConfiguredByUri()) { return new MongoClient(new MongoClientURI(clientConfig.getUri(), allOptions.options.get())); } else { return createMongoClient(clientName, clientConfig, allOptions.options.get().build()); } }
@Override public void onStartup(Set<Class<?>> classes, ServletContext servletContext) throws ServletException { WebConfig webConfig = Seed.baseConfiguration().get(WebConfig.class); servletContext.setSessionTrackingModes(of(valueOf(webConfig.getSessionTrackingMode().name()))); try { kernel = Seed.createKernel(servletContext, buildKernelConfiguration(servletContext), true); } catch (Exception e) { handleException(e); } servletContext.setAttribute(KERNEL_ATTRIBUTE_NAME, kernel); servletContext.setAttribute(INJECTOR_ATTRIBUTE_NAME, kernel.objectGraph().as(Injector.class)); servletContext.addListener(this); }
@Override @SuppressFBWarnings(value = "DM_EXIT", justification = "JmhLauncher must be able to return a code to the system") public void launch(String[] args) throws Exception { Coffig coffig = Seed.baseConfiguration(); JmhConfig jmhConfig = coffig.get(JmhConfig.class); if (jmhConfig.getMeasurement().getForks() == 0) { kernel = Seed.createKernel(); JmhPlugin jmhPlugin = getJmhPlugin(kernel); jmhPlugin.getRunner().run(); } else { new JmhRunnerFactory() .createRunner(jmhConfig) .run(); } System.exit(0); }
private MongoClientSettings buildMongoClientSettings(MongoDbConfig.ClientConfig clientConfig, String clientName, Coffig coffig) { MongoClientSettings.Builder settingsBuilder = MongoClientSettings.builder(); AllSettings allSettings = coffig.get(AllSettings.class, String.format("mongoDb.clients.%s.settings", clientName)); // Apply hosts List<String> hosts = clientConfig.getHosts(); if (hosts.size() > 0) { allSettings.cluster.get().hosts(buildServerAddresses(clientName, hosts)); } // Apply credentials settingsBuilder.credentialList(buildMongoCredentials(clientName, clientConfig.getCredentials())); // Apply global settings Optional.ofNullable(allSettings.readPreference).ifPresent(settingsBuilder::readPreference); Optional.ofNullable(allSettings.writeConcern).ifPresent(settingsBuilder::writeConcern); Optional.ofNullable(allSettings.codecRegistry).map(Classes::instantiateDefault).ifPresent(settingsBuilder::codecRegistry); // Apply sub-settings settingsBuilder.clusterSettings(allSettings.cluster.get().build()); settingsBuilder.socketSettings(allSettings.socket.get().build()); settingsBuilder.heartbeatSocketSettings(allSettings.heartbeatSocket.get().build()); settingsBuilder.connectionPoolSettings(allSettings.connectionPool.get().build()); settingsBuilder.serverSettings(allSettings.server.get().build()); settingsBuilder.sslSettings(allSettings.ssl.get().build()); return settingsBuilder.build(); }
@SuppressWarnings("unchecked") @Override public InitState init(InitContext initContext) { detectSystemPropertiesConfig(); detectKernelParamConfig(initContext); detectConfigurationFiles(initContext); CliContext cliContext = seedRuntime.contextAs(CliContext.class); application = new ApplicationImpl(coffig, initContext.kernelParams(), cliContext != null ? cliContext.getArgs() : new String[0]); configConfig = coffig.get(ConfigConfig.class); diagnosticManager.registerDiagnosticInfoCollector("application", new ApplicationDiagnosticCollector(application)); return InitState.INITIALIZED; }
private void createWorker(Coffig config) throws Exception { UndertowConfig undertowConfig = config.get(UndertowConfig.class); try { xnioWorker = Xnio.getInstance().createWorker(OptionMap.builder() .set(Options.WORKER_IO_THREADS, undertowConfig.getIoThreads()) .set(Options.WORKER_TASK_CORE_THREADS, undertowConfig.getWorkerThreads()) .set(Options.WORKER_TASK_MAX_THREADS, undertowConfig.getWorkerThreads()) .set(Options.TCP_NODELAY, true) .getMap()); } catch (RuntimeException e) { unwrapUndertowException(e); } }