public synchronized void updated(Dictionary dictionary) throws ConfigurationException { try { if(dictionary != null) { m_serverURL = new URL((String) dictionary.get(DiscoveryConstants.DISCOVERY_URL_KEY)); } } catch (MalformedURLException e) { throw new ConfigurationException(DiscoveryConstants.DISCOVERY_URL_KEY, "Malformed URL", e); } }
private int getInt(String property, int dflt) throws ConfigurationException { String value = (String) properties.get(property); if (value != null) { try { return Integer.parseInt(value); } catch (Exception e) { throw new ConfigurationException(property, "Error parsing " + property + "(" + value + ") property as an integer", e); } } return dflt; }
private boolean getBool(String property, boolean dflt) throws ConfigurationException { String value = (String) properties.get(property); if (value != null) { try { return Boolean.parseBoolean(value); } catch (Exception e) { throw new ConfigurationException(property, "Error parsing " + property + "(" + value + ") property as a boolean", e); } } return dflt; }
@SuppressWarnings("unchecked") static <ResultType> ResultType requireProperty(Dictionary<?, ?> props, String name, Class<ResultType> clazz) throws ConfigurationException { final Object o = props.get(name); if(o == null) { throw new ConfigurationException(name, "Missing required configuration property: " + name); } if( !( clazz.isAssignableFrom(o.getClass()))) { throw new ConfigurationException(name, "Property is not a " + clazz.getName()); } return (ResultType)o; }
private String getStringProperty(final Map<String, Object> componentProperties, final String propertyName) throws ConfigurationException { Object value = componentProperties.get(propertyName); if (value == null) { throw new ConfigurationException(propertyName, "property not defined"); } return String.valueOf(value); }
/** * Check the existence of the given dictionary. Throw an exception if null. */ public static void checkDictionary(Dictionary properties, ComponentContext componentContext) throws ConfigurationException { if (properties == null) { String dicName = componentContext.getProperties().get("service.pid").toString(); throw new ConfigurationException("*", "Dictionary for " + dicName + " does not exist"); } }
@Override public SSLContext getContext() throws ConfigurationException { try { SSLContext sslContext = SSLContext.getInstance("TLSv1.2"); sslContext.init(null, new TrustManager[] { trustManager }, null); return sslContext; } catch (KeyManagementException | NoSuchAlgorithmException e) { logger.warn("SSL configuration failed", e); throw new ConfigurationException("ssl", e.getMessage()); } } }
private static Properties DEFAULT_PROPERTIES = SomeUtil.getProperties("myclass.properties"); // Put this in a SomeUtil class. public static Properties getProperties(String filename) { Properties properties = new Properties(); try { properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)); } catch (IOException e) { throw new ConfigurationException("Cannot load " + filename, e); } return properties; }
public class A { private Properties properties; { try { properties = new Properties(); properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("file.properties")); } catch (IOException e) { throw new ConfigurationException("Failed to load properties file.", e); // It's a subclass of RuntimeException. } } // ... }
@Activate protected void activate(DispatcherMaxAgeHeaderFilter.Config config) throws Exception { maxage = config.max_age(); if (maxage < 0) { throw new ConfigurationException("max.age", "Max Age must be specified and greater than 0."); } }
static boolean getBool(Dictionary properties, String property, boolean dflt) throws ConfigurationException { String value = (String) properties.get(property); if (value != null) { try { return Boolean.parseBoolean(value); } catch (Exception e) { throw new ConfigurationException(property, NLS.MESSAGES.getMessage("prop.value.not.boolean", property, value), e); } } return dflt; }
@Override protected void doActivate(ComponentContext context) throws Exception { Dictionary<?, ?> properties = context.getProperties(); maxage = PropertiesUtil.toLong(properties.get(PROP_MAX_AGE), -1); if (maxage < 0) { throw new ConfigurationException(PROP_MAX_AGE, "Max Age must be specified and greater than 0."); } }
private String getMandatoryString(Dictionary properties, String key) throws ConfigurationException { String value = getOptionalString(properties, key); if (value == null) { throw new ConfigurationException(key, "missing value"); } return value; }
public static synchronized void configure(SlingSettingsService slingSettings) throws ConfigurationException { runmodes = slingSettings.getRunModes(); isAuthor = runmodes.contains(Externalizer.AUTHOR); isPublish = runmodes.contains(Externalizer.PUBLISH); if (isAuthor && isPublish) { throw new ConfigurationException(null, "Either 'author' or 'publish' run modes may be specified, not both."); } }
public static synchronized void configure(SlingSettingsService slingSettings) throws ConfigurationException { runmodes = slingSettings.getRunModes(); isAuthor = runmodes.contains(Externalizer.AUTHOR); isPublish = runmodes.contains(Externalizer.PUBLISH); if (isAuthor && isPublish) { throw new ConfigurationException(null, "Either 'author' or 'publish' run modes may be specified, not both."); } }
private static Properties DEFAULT_PROPERTIES = getDefaultProperties(); private static Properties getDefaultProperties() { Properties properties = new Properties(); try { properties.load(MyClass.class.getResourceAsStream("myclass.properties")); } catch (IOException e) { throw new ConfigurationException("Cannot load properties file", e); } return properties; }
@Override protected void doActivate(ComponentContext context) throws Exception { super.doActivate(context); @SuppressWarnings("unchecked") Dictionary<String, Object> props = context.getProperties(); dayOfWeek = PropertiesUtil.toInteger(props.get(PROP_EXPIRES_DAY_OF_WEEK), -1); if (dayOfWeek < Calendar.SUNDAY || dayOfWeek > Calendar.SATURDAY) { throw new ConfigurationException("expires.dayofweek", "Day of week must be valid value from Calendar DAY_OF_WEEK attribute."); } } }
public synchronized void updated(String pid, Properties properties) throws ConfigurationException { try { deleted(pid); configurations.put(pid, new ClusteredConfiguration(properties)); } catch (Exception e) { ConfigurationException configurationException = new ConfigurationException(null, "Unable to parse ActiveMQ configuration: " + e.getMessage()); configurationException.initCause(e); throw configurationException; } }
@Override protected LifecycleAware getConfigurationDrivenResource(BundleContext context, String pid, Map<String, Object> properties) throws Exception { Properties jdbcProps = getJdbcProps(pid, properties); try { return new ManagedJDBCResourceProvider(context, pid, jdbcProps, properties); } catch (InvalidSyntaxException e) { LOG.error("The configuration {} contained an invalid target filter {}", pid, e.getFilter()); throw new ConfigurationException(DSF_TARGET_FILTER, "The target filter was invalid", e); } }
@Override public void updated(Dictionary dict) throws ConfigurationException { this.cachedConfig = dict; LOG.info("Updating BAI ConfigAdmin from " + dict); try { OsgiPropertiesPolicySetSlurper slurper = new OsgiPropertiesPolicySetSlurper(dict, getBundleContext(), fileWatcher); setPolicySet(slurper.slurpXml()); } catch (Exception e) { throw new ConfigurationException(OsgiPropertiesPolicySetSlurper.BAI_XML_PROPERTY, e.getMessage(), e); } }