List of usage examples for org.apache.commons.configuration Configuration getInt
int getInt(String key, int defaultValue);
From source file:org.restcomm.connect.http.RecordingsEndpoint.java
@PostConstruct public void init() { final DaoManager storage = (DaoManager) context.getAttribute(DaoManager.class.getName()); configuration = (Configuration) context.getAttribute(Configuration.class.getName()); Configuration amazonS3Configuration = configuration.subset("amazon-s3"); configuration = configuration.subset("runtime-settings"); super.init(configuration); dao = storage.getRecordingsDao();/*from ww w . j av a 2 s. c o m*/ final RecordingConverter converter = new RecordingConverter(configuration); listConverter = new RecordingListConverter(configuration); final GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(Recording.class, converter); builder.registerTypeAdapter(RecordingList.class, listConverter); builder.setPrettyPrinting(); gson = builder.create(); xstream = new XStream(); xstream.alias("RestcommResponse", RestCommResponse.class); xstream.registerConverter(converter); xstream.registerConverter(new RecordingListConverter(configuration)); xstream.registerConverter(new RestCommResponseConverter(configuration)); if (!amazonS3Configuration.isEmpty()) { // Do not fail with NPE is amazonS3Configuration is not present for older install boolean amazonS3Enabled = amazonS3Configuration.getBoolean("enabled"); if (amazonS3Enabled) { final String accessKey = amazonS3Configuration.getString("access-key"); final String securityKey = amazonS3Configuration.getString("security-key"); final String bucketName = amazonS3Configuration.getString("bucket-name"); final String bucketFolder = amazonS3Configuration.getString("folder"); final boolean reducedRedundancy = amazonS3Configuration.getBoolean("reduced-redundancy"); final int minutesToRetainPublicUrl = amazonS3Configuration.getInt("minutes-to-retain-public-url", 10); final boolean removeOriginalFile = amazonS3Configuration.getBoolean("remove-original-file"); final String bucketRegion = amazonS3Configuration.getString("bucket-region"); final boolean testing = amazonS3Configuration.getBoolean("testing", false); final String testingUrl = amazonS3Configuration.getString("testing-url", null); s3AccessTool = new S3AccessTool(accessKey, securityKey, bucketName, bucketFolder, reducedRedundancy, minutesToRetainPublicUrl, removeOriginalFile, bucketRegion, testing, testingUrl); securityLevel = RecordingSecurityLevel .valueOf(amazonS3Configuration.getString("security-level", "secure").toUpperCase()); converter.setSecurityLevel(securityLevel); } } xstream.registerConverter(listConverter); instanceId = RestcommConfiguration.getInstance().getMain().getInstanceId(); }
From source file:org.restcomm.connect.telephony.CallManager.java
public CallManager(final Configuration configuration, final ServletContext context, final MediaServerControllerFactory msControllerFactory, final ActorRef conferences, final ActorRef bridges, final ActorRef sms, final SipFactory factory, final DaoManager storage) { super();//from w ww. java2 s .c o m this.system = context().system(); this.configuration = configuration; this.context = context; this.msControllerFactory = msControllerFactory; this.conferences = conferences; this.bridges = bridges; this.sms = sms; this.sipFactory = factory; this.storage = storage; final Configuration runtime = configuration.subset("runtime-settings"); final Configuration outboundProxyConfig = runtime.subset("outbound-proxy"); SipURI outboundIntf = outboundInterface("udp"); if (outboundIntf != null) { myHostIp = ((SipURI) outboundIntf).getHost().toString(); } else { String errMsg = "SipURI outboundIntf is null"; sendNotification(errMsg, 14001, "error", false); if (context == null) errMsg = "SipServlet context is null"; sendNotification(errMsg, 14002, "error", false); } Configuration mediaConf = configuration.subset("media-server-manager"); mediaExternalIp = mediaConf.getString("mgcp-server.external-address"); proxyIp = runtime.subset("telestax-proxy").getString("uri").replaceAll("http://", "").replaceAll(":2080", ""); if (mediaExternalIp == null || mediaExternalIp.isEmpty()) mediaExternalIp = myHostIp; if (proxyIp == null || proxyIp.isEmpty()) proxyIp = myHostIp; this.useTo = runtime.getBoolean("use-to"); this.authenticateUsers = runtime.getBoolean("authenticate"); this.primaryProxyUri = outboundProxyConfig.getString("outbound-proxy-uri"); this.primaryProxyUsername = outboundProxyConfig.getString("outbound-proxy-user"); this.primaryProxyPassword = outboundProxyConfig.getString("outbound-proxy-password"); this.fallBackProxyUri = outboundProxyConfig.getString("fallback-outbound-proxy-uri"); this.fallBackProxyUsername = outboundProxyConfig.getString("fallback-outbound-proxy-user"); this.fallBackProxyPassword = outboundProxyConfig.getString("fallback-outbound-proxy-password"); this.activeProxy = primaryProxyUri; this.activeProxyUsername = primaryProxyUsername; this.activeProxyPassword = primaryProxyPassword; numberOfFailedCalls = new AtomicInteger(); numberOfFailedCalls.set(0); useFallbackProxy = new AtomicBoolean(); useFallbackProxy.set(false); allowFallback = outboundProxyConfig.getBoolean("allow-fallback", false); maxNumberOfFailedCalls = outboundProxyConfig.getInt("max-failed-calls", 20); allowFallbackToPrimary = outboundProxyConfig.getBoolean("allow-fallback-to-primary", false); patchForNatB2BUASessions = runtime.getBoolean("patch-for-nat-b2bua-sessions", true); //Monitoring Service this.monitoring = (ActorRef) context.getAttribute(MonitoringService.class.getName()); extensions = ExtensionController.getInstance().getExtensions(ExtensionType.CallManager); if (logger.isInfoEnabled()) { logger.info("CallManager extensions: " + (extensions != null ? extensions.size() : "0")); } if (!runtime.subset("ims-authentication").isEmpty()) { final Configuration imsAuthentication = runtime.subset("ims-authentication"); this.actAsImsUa = imsAuthentication.getBoolean("act-as-ims-ua"); if (actAsImsUa) { this.imsProxyAddress = imsAuthentication.getString("proxy-address"); this.imsProxyPort = imsAuthentication.getInt("proxy-port"); if (imsProxyPort == 0) { imsProxyPort = DEFAUL_IMS_PROXY_PORT; } this.imsDomain = imsAuthentication.getString("domain"); this.imsAccount = imsAuthentication.getString("account"); if (actAsImsUa && (imsProxyAddress == null || imsProxyAddress.isEmpty() || imsDomain == null || imsDomain.isEmpty())) { logger.warning("ims proxy-address or domain is not configured"); } this.actAsImsUa = actAsImsUa && imsProxyAddress != null && !imsProxyAddress.isEmpty() && imsDomain != null && !imsDomain.isEmpty(); } } firstTimeCleanup(); }
From source file:org.restcomm.connect.telephony.ua.UserAgentManager.java
public UserAgentManager(final Configuration configuration, final SipFactory factory, final DaoManager storage, final ServletContext servletContext) { super();/*from w w w .j av a 2 s . co m*/ // this.configuration = configuration; this.servletContext = servletContext; monitoringService = (ActorRef) servletContext.getAttribute(MonitoringService.class.getName()); final Configuration runtime = configuration.subset("runtime-settings"); this.authenticateUsers = runtime.getBoolean("authenticate"); this.factory = factory; this.storage = storage; pingInterval = runtime.getInt("ping-interval", 60); logger.info("About to run firstTimeCleanup()"); instanceId = RestcommConfiguration.getInstance().getMain().getInstanceId(); if (!runtime.subset("ims-authentication").isEmpty()) { final Configuration imsAuthentication = runtime.subset("ims-authentication"); this.actAsImsUa = imsAuthentication.getBoolean("act-as-ims-ua"); if (actAsImsUa) { this.imsProxyAddress = imsAuthentication.getString("proxy-address"); this.imsProxyPort = imsAuthentication.getInt("proxy-port"); if (imsProxyPort == 0) { imsProxyPort = DEFAUL_IMS_PROXY_PORT; } this.imsDomain = imsAuthentication.getString("domain"); if (actAsImsUa && (imsProxyAddress == null || imsProxyAddress.isEmpty() || imsDomain == null || imsDomain.isEmpty())) { logger.warning("ims proxy-address or domain is not configured"); } this.actAsImsUa = actAsImsUa && imsProxyAddress != null && !imsProxyAddress.isEmpty() && imsDomain != null && !imsDomain.isEmpty(); } } firstTimeCleanup(); }
From source file:org.roda.core.RodaCoreFactory.java
/** * Start ApacheDS.//from ww w .j a v a 2 s . c o m */ private static void startApacheDS() { rodaApacheDSDataDirectory = RodaCoreFactory.getDataPath().resolve(RodaConstants.CORE_LDAP_FOLDER); try { final Configuration rodaConfig = RodaCoreFactory.getRodaConfiguration(); final boolean ldapStartServer = rodaConfig.getBoolean("ldap.startServer", false); final int ldapPort = rodaConfig.getInt("ldap.port", RodaConstants.CORE_LDAP_DEFAULT_PORT); final String ldapBaseDN = rodaConfig.getString("ldap.baseDN", "dc=roda,dc=org"); final String ldapPeopleDN = rodaConfig.getString("ldap.peopleDN", "ou=users,dc=roda,dc=org"); final String ldapGroupsDN = rodaConfig.getString("ldap.groupsDN", "ou=groups,dc=roda,dc=org"); final String ldapRolesDN = rodaConfig.getString("ldap.rolesDN", "ou=groups,dc=roda,dc=org"); final String ldapAdminDN = rodaConfig.getString("ldap.adminDN", "ou=groups,dc=roda,dc=org"); final String ldapAdminPassword = rodaConfig.getString("ldap.adminPassword", "roda"); final String ldapPasswordDigestAlgorithm = rodaConfig.getString("ldap.passwordDigestAlgorithm", "MD5"); final List<String> ldapProtectedUsers = RodaUtils.copyList(rodaConfig.getList("ldap.protectedUsers")); final List<String> ldapProtectedGroups = RodaUtils.copyList(rodaConfig.getList("ldap.protectedGroups")); final String rodaGuestDN = rodaConfig.getString("ldap.rodaGuestDN", "uid=guest,ou=users,dc=roda,dc=org"); final String rodaAdminDN = rodaConfig.getString("ldap.rodaAdminDN", "uid=admin,ou=users,dc=roda,dc=org"); final String rodaAdministratorsDN = rodaConfig.getString("ldap.rodaAdministratorsDN", "cn=administrators,ou=groups,dc=roda,dc=org"); RodaCoreFactory.ldapUtility = new LdapUtility(ldapStartServer, ldapPort, ldapBaseDN, ldapPeopleDN, ldapGroupsDN, ldapRolesDN, ldapAdminDN, ldapAdminPassword, ldapPasswordDigestAlgorithm, ldapProtectedUsers, ldapProtectedGroups, rodaGuestDN, rodaAdminDN, rodaApacheDSDataDirectory); ldapUtility.setRODAAdministratorsDN(rodaAdministratorsDN); UserUtility.setLdapUtility(ldapUtility); if (!FSUtils.exists(rodaApacheDSDataDirectory)) { Files.createDirectories(rodaApacheDSDataDirectory); final List<String> ldifFileNames = Arrays.asList("users.ldif", "groups.ldif", "roles.ldif"); final List<String> ldifs = new ArrayList<>(); for (String ldifFileName : ldifFileNames) { final InputStream ldifInputStream = RodaCoreFactory .getConfigurationFileAsStream(RodaConstants.CORE_LDAP_FOLDER + "/" + ldifFileName); ldifs.add(IOUtils.toString(ldifInputStream, RodaConstants.DEFAULT_ENCODING)); RodaUtils.closeQuietly(ldifInputStream); } RodaCoreFactory.ldapUtility.initDirectoryService(ldifs); indexUsersAndGroupsFromLDAP(); } else { RodaCoreFactory.ldapUtility.initDirectoryService(); } createRoles(rodaConfig); indexUsersAndGroupsFromLDAP(); } catch (final Exception e) { LOGGER.error("Error starting up embedded ApacheDS", e); instantiatedWithoutErrors = false; } }
From source file:org.seedstack.i18n.internal.I18nCacheProvider.java
@Singleton @Override/*from w ww. j av a2s . c om*/ public LoadingCache<String, Map<String, String>> get() { Configuration configuration = application.getConfiguration(); int cacheSize = configuration.getInt("org.seedstack.i18n.cache.max-size", DEFAULT_CACHE_SIZE); return CacheBuilder.newBuilder().maximumSize(cacheSize) .concurrencyLevel( configuration.getInt("org.seedstack.i18n.cache.concurrency", DEFAULT_CACHE_CONCURRENCY)) .initialCapacity(configuration.getInt("org.seedstack.i18n.cache.initial-size", cacheSize / 4)) .build(i18nCacheLoader); }
From source file:org.seedstack.jms.internal.JmsFactoryImpl.java
@Override @SuppressWarnings("unchecked") public ConnectionDefinition createConnectionDefinition(String connectionName, Configuration configuration, ConnectionFactory connectionFactory) { // Find connection factory if not given explicitly if (connectionFactory == null) { connectionFactory = connectionFactoryMap.get(configuration.getString("connection-factory")); if (connectionFactory == null) { throw SeedException.createNew(JmsErrorCodes.MISSING_CONNECTION_FACTORY).put("connectionName", connectionName);/*from w ww. j a va 2 s .c om*/ } } // Create exception listener String exceptionListenerClassName = configuration.getString("exception-listener"); Class<? extends ExceptionListener> exceptionListener = null; if (StringUtils.isNotBlank(exceptionListenerClassName)) { try { exceptionListener = (Class<? extends ExceptionListener>) Class.forName(exceptionListenerClassName); } catch (Exception e) { throw new PluginException( "Unable to load JMS ExceptionListener class " + exceptionListenerClassName, e); } } // Create exception handler String exceptionHandlerClassName = configuration.getString("exception-handler"); Class<? extends JmsExceptionHandler> exceptionHandler = null; if (StringUtils.isNotBlank(exceptionHandlerClassName)) { try { exceptionHandler = (Class<? extends JmsExceptionHandler>) Class.forName(exceptionHandlerClassName); } catch (Exception e) { throw SeedException.wrap(e, JmsErrorCodes.UNABLE_TO_LOAD_CLASS).put("exceptionHandler", exceptionHandlerClassName); } } boolean jeeMode = configuration.getBoolean("jee-mode", false); boolean shouldSetClientId = configuration.getBoolean("set-client-id", !jeeMode); if (jeeMode && shouldSetClientId) { throw SeedException.createNew(JmsErrorCodes.CANNOT_SET_CLIENT_ID_IN_JEE_MODE) .put(JmsPlugin.ERROR_CONNECTION_NAME, connectionName); } return new ConnectionDefinition(connectionName, connectionFactory, configuration.getBoolean("managed-connection", true), jeeMode, shouldSetClientId, configuration.getString("client-id", applicationName + "-" + connectionName), configuration.getString("user"), configuration.getString("password"), configuration.getInt("reconnection-delay", DEFAULT_RECONNECTION_DELAY), exceptionListener, exceptionHandler); }
From source file:org.seedstack.ldap.internal.LdapPlugin.java
@Override public InitState init(InitContext initContext) { Configuration configuration = initContext.dependency(ConfigurationProvider.class).getConfiguration(); String[] realms = configuration.getStringArray(CHOSEN_REALMS); startPlugin = ArrayUtils.contains(realms, LdapRealm.class.getSimpleName()); if (startPlugin) { Configuration ldapConfiguration = configuration.subset(LDAP_CONFIG_PREFIX); // Initialize ldap pool connection String host = ldapConfiguration.getString(SERVER_HOST_PROP); if (host == null) { throw SeedException.createNew(LdapErrorCodes.NO_HOST_DEFINED).put("hostPropName", LDAP_CONFIG_PREFIX + "." + SERVER_HOST_PROP); }/*from www.j a v a 2s . c o m*/ int port = ldapConfiguration.getInt(SERVER_PORT_PROP, DEFAULT_SERVER_PORT); int numConnections = ldapConfiguration.getInt(NUM_CONNECTIONS_PROP, DEFAULT_NUM_CONNECTIONS); String accountDn = StringUtils.join(ldapConfiguration.getStringArray(ACCOUNT_DN_PROP), ','); LDAPConnection connection; try { connection = new LDAPConnection(host, port, accountDn, ldapConfiguration.getString(ACCOUNT_PASSWORD_PROP)); ldapConnectionPool = new LDAPConnectionPool(connection, numConnections); } catch (LDAPException e) { switch (e.getResultCode().intValue()) { case ResultCode.NO_SUCH_OBJECT_INT_VALUE: throw SeedException.wrap(e, LdapErrorCodes.NO_SUCH_ACCOUNT).put("account", accountDn) .put("propName", LDAP_CONFIG_PREFIX + "." + ACCOUNT_DN_PROP); case ResultCode.INVALID_CREDENTIALS_INT_VALUE: throw SeedException.wrap(e, LdapErrorCodes.INVALID_CREDENTIALS).put("account", accountDn) .put("passwordPropName", LDAP_CONFIG_PREFIX + "." + ACCOUNT_PASSWORD_PROP) .put("userPropName", LDAP_CONFIG_PREFIX + "." + ACCOUNT_DN_PROP); case ResultCode.CONNECT_ERROR_INT_VALUE: throw SeedException.wrap(e, LdapErrorCodes.CONNECT_ERROR).put("host", host).put("port", port) .put("hostPropName", LDAP_CONFIG_PREFIX + "." + SERVER_HOST_PROP) .put("portPropName", LDAP_CONFIG_PREFIX + "." + SERVER_PORT_PROP); default: throw SeedException.wrap(e, LdapErrorCodes.LDAP_ERROR).put("message", e.getMessage()) .put("host", host).put("port", port).put("account", accountDn); } } } return InitState.INITIALIZED; }
From source file:org.seedstack.mqtt.internal.MqttPoolDefinition.java
public MqttPoolDefinition(Configuration configuration) { this.available = configuration.getBoolean(POOL_ENABLED, Boolean.TRUE); if (this.available) { int coreSize = configuration.getInt(POOL_CORE_SIZE, DEFAULT_CORE_SIZE); int maxSize = configuration.getInt(POOL_MAX_SIZE, DEFAULT_MAX_SIZE); int queueSize = configuration.getInt(POOL_QUEUE_SIZE, DEFAULT_QUEUE_SIZE); int keepAlive = configuration.getInt(POOL_KEEP_ALIVE, DEFAULT_KEEP_ALIVE); this.threadPoolExecutor = new ThreadPoolExecutor(coreSize, maxSize, keepAlive, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(queueSize)); }/*from w ww . ja v a 2 s . c o m*/ }
From source file:org.seedstack.seed.security.ldap.internal.LdapSecurityPlugin.java
@Override public InitState init(InitContext initContext) { ApplicationPlugin appPlugin = (ApplicationPlugin) initContext.pluginsRequired().iterator().next(); String[] realms = appPlugin.getApplication().getConfiguration().getStringArray(CHOSEN_REALMS); startPlugin = ArrayUtils.contains(realms, LDAPRealm.class.getSimpleName()); if (startPlugin) { Configuration ldapConfiguration = appPlugin.getApplication().getConfiguration() .subset(LDAP_CONFIG_PREFIX); // Initialize ldap pool connection String host = ldapConfiguration.getString(SERVER_HOST_PROP); if (host == null) { throw SeedException.createNew(LDAPErrorCode.NO_HOST_DEFINED).put("hostPropName", LDAP_CONFIG_PREFIX + "." + SERVER_HOST_PROP); }/* www. j a va 2 s .c om*/ int port = ldapConfiguration.getInt(SERVER_PORT_PROP, DEFAULT_SERVER_PORT); int numConnections = ldapConfiguration.getInt(NUM_CONNECTIONS_PROP, DEFAULT_NUM_CONNECTIONS); String accountDn = StringUtils.join(ldapConfiguration.getStringArray(ACCOUNT_DN_PROP), ','); LDAPConnection connection; try { connection = new LDAPConnection(host, port, accountDn, ldapConfiguration.getString(ACCOUNT_PASSWORD_PROP)); ldapConnectionPool = new LDAPConnectionPool(connection, numConnections); } catch (LDAPException e) { switch (e.getResultCode().intValue()) { case ResultCode.NO_SUCH_OBJECT_INT_VALUE: throw SeedException.wrap(e, LDAPErrorCode.NO_SUCH_ACCOUNT).put("account", accountDn) .put("propName", LDAP_CONFIG_PREFIX + "." + ACCOUNT_DN_PROP); case ResultCode.INVALID_CREDENTIALS_INT_VALUE: throw SeedException.wrap(e, LDAPErrorCode.INVALID_CREDENTIALS).put("account", accountDn) .put("passwordPropName", LDAP_CONFIG_PREFIX + "." + ACCOUNT_PASSWORD_PROP) .put("userPropName", LDAP_CONFIG_PREFIX + "." + ACCOUNT_DN_PROP); case ResultCode.CONNECT_ERROR_INT_VALUE: throw SeedException.wrap(e, LDAPErrorCode.CONNECT_ERROR).put("host", host).put("port", port) .put("hostPropName", LDAP_CONFIG_PREFIX + "." + SERVER_HOST_PROP) .put("portPropName", LDAP_CONFIG_PREFIX + "." + SERVER_PORT_PROP); default: throw SeedException.wrap(e, LDAPErrorCode.LDAP_ERROR).put("message", e.getMessage()) .put("host", host).put("port", port).put("account", accountDn); } } } return InitState.INITIALIZED; }
From source file:org.seedstack.seed.shell.internal.ShellPlugin.java
@Override public InitState init(InitContext initContext) { ApplicationPlugin applicationPlugin = (ApplicationPlugin) initContext.pluginsRequired().iterator().next(); org.apache.commons.configuration.Configuration shellConfiguration = applicationPlugin.getApplication() .getConfiguration().subset(ShellPlugin.SHELL_PLUGIN_CONFIGURATION_PREFIX); // No need to go further if shell is not enabled if (!shellConfiguration.getBoolean("enabled", false)) { LOGGER.info("Shell support is present in the classpath but not enabled"); return InitState.INITIALIZED; }/* w w w .j a v a 2 s .c om*/ port = shellConfiguration.getInt("port", SHELL_DEFAULT_PORT); sshServer = SshServer.setUpDefaultServer(); sshServer.setPort(port); String keyType = shellConfiguration.getString("key.type", "generated"); if ("generated".equals(keyType)) { File storage; try { storage = applicationPlugin.getApplication().getStorageLocation("shell"); } catch (IOException e) { throw new PluginException("Unable to acces storage location for context shell", e); } sshServer.setKeyPairProvider( new SimpleGeneratorHostKeyProvider(new File(storage, "generate-key.ser").getAbsolutePath())); } else if ("file".equals(keyType)) { sshServer.setKeyPairProvider( new FileKeyPairProvider(new String[] { shellConfiguration.getString("key.location") })); } else if ("resource".equals(keyType)) { sshServer.setKeyPairProvider( new ResourceKeyPairProvider(new String[] { shellConfiguration.getString("key.location") })); } sshServer.setShellFactory(new Factory<Command>() { @Override public Command create() { return shellFactory.createInteractiveShell(); } }); sshServer.setCommandFactory(new CommandFactory() { @Override public Command createCommand(String command) { return shellFactory.createNonInteractiveShell(command); } }); return InitState.INITIALIZED; }