Java Code Examples for org.apache.deltaspike.core.api.config.ConfigResolver#getPropertyValue()

The following examples show how to use org.apache.deltaspike.core.api.config.ConfigResolver#getPropertyValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NotEqualPropertyExpressionInterpreter.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Override
public Boolean evaluate(String expression) {
    if (expression == null) {
        return false;
    }
    
    String[] values = expression.split("!=");
    
    if (values.length != 2) {
        throw new IllegalArgumentException("'" + expression + "' is not a supported syntax");
    }
    
    String configuredValue = ConfigResolver.getPropertyValue(values[0], null);
    
    // exclude if null or the configured value is different
    return configuredValue == null || !values[1].trim().equalsIgnoreCase(configuredValue);
}
 
Example 2
Source File: ServletConfigListener.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
private void setServletConfig(ServletConfigSource configSource, ServletContextEvent sce)
{
    ServletContext servletContext = sce.getServletContext();
    String servletContextName = servletContext.getServletContextName();
    if (servletContextName != null && servletContextName.length() > 0)
    {
        String oldAppName = ConfigResolver.getPropertyValue(ConfigResolver.DELTASPIKE_APP_NAME_CONFIG);

        // we first need to unregister the old MBean
        // as we don't know whether the CDI Extension or the Servlet Listener comes first.
        // It's simply not defined by the spec :/
        ConfigurationExtension.unRegisterConfigMBean(oldAppName);

        configSource.setPropertyValue(ConfigResolver.DELTASPIKE_APP_NAME_CONFIG, servletContextName);

        // and as we now did set the new name -> register again:
        ConfigurationExtension.registerConfigMBean();
    }
}
 
Example 3
Source File: ProjectStageProducer.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
/**
 * Resolves the project-stage configured for DeltaSpike
 * @return the resolved {@link ProjectStage} or <code>null</code> if none defined.
 */
protected ProjectStage resolveProjectStage()
{
    for (String configLocation : CONFIG_SETTING_KEYS)
    {
        String stageName = ConfigResolver.getPropertyValue(configLocation);

        if (stageName != null && !stageName.isEmpty())
        {
            return ProjectStage.valueOf(stageName);
        }

    }

    return null;
}
 
Example 4
Source File: DefaultClassDeactivator.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
@Override
public Boolean isActivated(Class<? extends Deactivatable> targetClass)
{
    final String key = KEY_PREFIX + targetClass.getName();
    final String value = ConfigResolver.getPropertyValue(key);
    if (value == null)
    {
        return null;
    }
    else
    {
        if (LOG.isLoggable(Level.FINE))
        {
            LOG.log(Level.FINE, "Deactivation setting for {0} found to be {1} based on configuration.",
                    new Object[]{key, value});
        }
        return !Boolean.valueOf(value);
    }
}
 
Example 5
Source File: DynamicMBeanWrapper.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
private String getDescription(final String description, String defaultDescription)
{
    if (description.isEmpty())
    {
        return defaultDescription;
    }

    String descriptionValue = description.trim();

    if (descriptionValue.startsWith("{") && descriptionValue.endsWith("}"))
    {
        return ConfigResolver.getPropertyValue(
            descriptionValue.substring(1, descriptionValue.length() - 1), defaultDescription);
    }
    return description;
}
 
Example 6
Source File: ConfigurationExtension.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
public static void registerConfigMBean()
{
    String appName = ConfigResolver.getPropertyValue(ConfigResolver.DELTASPIKE_APP_NAME_CONFIG);
    if (appName != null && appName.length() > 0)
    {
        try
        {
            MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

            ClassLoader tccl = ClassUtils.getClassLoader(ConfigurationExtension.class);
            DeltaSpikeConfigInfo cfgMBean = new DeltaSpikeConfigInfo(tccl);

            ObjectName name = new ObjectName("deltaspike.config." + appName + ":type=DeltaSpikeConfig");
            mBeanServer.registerMBean(cfgMBean, name);
        }
        catch (InstanceAlreadyExistsException iae)
        {
            // all fine, the CfgBean got already registered.
            // Most probably by the ServletConfigListener
        }
        catch (Exception e)
        {
            throw new RuntimeException(e);
        }
    }
}
 
Example 7
Source File: ConfigSourceTest.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
@Test
public void testConfigViaSystemProperty()
{
    String key = "testProperty01";
    String value = "test_value_01";

    // the value is not yet configured
    String configuredValue = ConfigResolver.getPropertyValue(key);
    Assert.assertNull(configuredValue);

    String myDefaultValue = "theDefaultValueDummy";
    configuredValue = ConfigResolver.getPropertyValue(key, myDefaultValue);
    Assert.assertEquals(myDefaultValue, configuredValue);

    // now we set a value for the config key
    System.setProperty(key, value);
    configuredValue = ConfigResolver.getPropertyValue(key);
    Assert.assertEquals(value, configuredValue);

    System.setProperty(key, "");
    configuredValue = ConfigResolver.getPropertyValue(key);
    Assert.assertEquals("", configuredValue);

}
 
Example 8
Source File: ConfigSourceTest.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Test
public void testEnvProperties() {
    String javaHome = System.getenv("JAVA_HOME");
    if (javaHome == null || javaHome.isEmpty())
    {
        // weird, should exist. Anyway, in that case we cannot test it.
        return;
    }

    // we search for JAVA.HOME which should also give us JAVA_HOME
    String value = ConfigResolver.getPropertyValue("JAVA.HOME");
    Assert.assertNotNull(value);
    Assert.assertEquals(javaHome, value);
}
 
Example 9
Source File: ConfigSourceTest.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigFilter()
{
    String secretVal = ConfigResolver.getPropertyValue("my.very.secret");
    Assert.assertNotNull(secretVal);
    Assert.assertEquals("a secret value: onlyIDoKnowIt", secretVal);
}
 
Example 10
Source File: ConfigSourceTest.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigViaMetaInfPropertyFile()
{
    String key = "testProperty03";
    String value = "test_value_03";

    String configuredValue = ConfigResolver.getPropertyValue(key);
    Assert.assertEquals(value, configuredValue);
}
 
Example 11
Source File: ConfigSourceTest.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigUninitializedDefaultValue()
{
    String key = "nonexistingProperty01";

    // passing in null as default value should work fine
    String configuredValue = ConfigResolver.getPropertyValue(key, null);
    Assert.assertNull(configuredValue);

    String myDefaultValue = "theDefaultValueDummy";
    configuredValue = ConfigResolver.getPropertyValue(key, myDefaultValue);
    Assert.assertEquals(myDefaultValue, configuredValue);
}
 
Example 12
Source File: ConfigSourceTest.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigViaClasspathPropertyFile()
{
    String key = "testProperty02";
    String value = "test_value_02";

    String configuredValue = ConfigResolver.getPropertyValue(key);
    Assert.assertEquals(value, configuredValue);
}
 
Example 13
Source File: ConfigResolverTest.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigVariableRecursiveDeclaration()
{
    String url = ConfigResolver.getPropertyValue("deltaspike.test.recursive.variable1", "", true);
    Assert.assertEquals("pre-crazy-post/ohgosh/crazy", url);

    ConfigResolver.TypedResolver<String> tr = ConfigResolver.resolve("deltaspike.test.recursive.variable1")
        .evaluateVariables(true).logChanges(true);
    Assert.assertEquals("pre-crazy-post/ohgosh/crazy", tr.getValue());
}
 
Example 14
Source File: ConfigResolverTest.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Test
public void testOverruledValue()
{
    String result = ConfigResolver.getPropertyValue("test");

    Assert.assertEquals("test2", result);
}
 
Example 15
Source File: ConfigurationExtension.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
/**
 * This method triggers freeing of the ConfigSources.
 */
@SuppressWarnings("UnusedDeclaration")
public void freeConfigSources(@Observes BeforeShutdown bs)
{
    String appName = ConfigResolver.getPropertyValue(ConfigResolver.DELTASPIKE_APP_NAME_CONFIG);
    unRegisterConfigMBean(appName);

    ConfigResolver.freeConfigSources();
    detectedParentPropertyFileConfigs.remove(ClassUtils.getClassLoader(null));

    // we also free the ClassDeactivationUtils cache
    ClassDeactivationUtils.clearCache();
}
 
Example 16
Source File: MBeanExtension.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
private String getConfigurableAttribute(final String annotationAttributeValue, final String defaultValue)
{
    String val = annotationAttributeValue.trim();
    if (val.startsWith("{") && val.endsWith("}"))
    {
        val = ConfigResolver.getPropertyValue(val.substring(1, val.length() - 1), defaultValue);
    }
    return val == null || val.isEmpty() ? defaultValue : val;
}
 
Example 17
Source File: InterDynExtension.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
public void init()
{
    Set<String> ruleConfigKeys = new HashSet<String>();

    // first we collect all the rule property names
    for (String propertyName : ConfigResolver.getAllProperties().keySet())
    {
        if (propertyName.startsWith(CoreBaseConfig.InterDynCustomization.INTERDYN_RULE_PREFIX) &&
            propertyName.contains(".match"))
        {
            ruleConfigKeys.add(propertyName.substring(0, propertyName.indexOf(".match")));
        }
    }

    for (String ruleConfigKey : ruleConfigKeys)
    {
        String match = ConfigResolver.getPropertyValue(ruleConfigKey + ".match");
        String annotationClassName = ConfigResolver.getPropertyValue(ruleConfigKey + ".annotation");

        if (match != null && annotationClassName != null &&
            match.length() > 0 && annotationClassName.length() > 0)
        {
            Annotation anno = getAnnotationImplementation(annotationClassName);
            boolean requiresProxy = anno.annotationType().getAnnotation(InterceptorBinding.class) != null;
            interceptorRules.add(new AnnotationRule(match, anno, requiresProxy));
        }
    }


    if (interceptorRules.isEmpty())
    {
        enabled = false;
    }
}
 
Example 18
Source File: TestBeanClassFilter.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isFiltered(Class<?> targetClass)
{
    if (!targetClass.getName().startsWith("org.apache.deltaspike.test."))
    {
        return false;
    }

    String currentTestOrigin = ConfigResolver.getPropertyValue(TestControl.class.getName());

    if (currentTestOrigin == null) //no known origin (no @TestControl is used)
    {
        //filter all classes which are located in packages using tests with class-filters
        //(since we test the feature with ambiguous beans which isn't valid without filtering)
        return getClass().getPackage().getName().equals(targetClass.getPackage().getName());
    }
    else
    {
        Class<?> currentOrigin = ClassUtils.tryToLoadClassForName(currentTestOrigin);
        //origin is in one of the packages for class-filtering tests
        if (getClass().getPackage().getName().equals(currentOrigin.getPackage().getName()))
        {
            TestControl testControl = currentOrigin.getAnnotation(TestControl.class);
            return ClassUtils.tryToInstantiateClass(testControl.classFilter()).isFiltered(targetClass);
        }
        return isInSamePackage(targetClass);
    }
}
 
Example 19
Source File: UserSession.java    From jpa-invoicer with The Unlicense 5 votes vote down vote up
@PostConstruct
public void init() {
    final String propertyValue = ConfigResolver.getPropertyValue(
            "jpa-invoicer.gpluskey");
    // If no Google OAuth API key available, use fake login
    if (StringUtils.isEmpty(propertyValue)) {
        demoLogin();
    }
}
 
Example 20
Source File: ConnectionPoolConfiguration.java    From datawave with Apache License 2.0 5 votes vote down vote up
public ConnectionPoolConfiguration(String poolName) {
    username = ConfigResolver.getPropertyValue("dw." + poolName + ".accumulo.userName");
    password = ConfigResolver.getPropertyValue("dw." + poolName + ".accumulo.password");
    instance = ConfigResolver.getPropertyValue("dw." + poolName + ".instanceName");
    zookeepers = ConfigResolver.getPropertyValue("dw." + poolName + ".zookeepers");
    lowPriorityPoolSize = Integer.parseInt(ConfigResolver.getPropertyValue("dw." + poolName + ".pool.low.size", "25"));
    normalPriorityPoolSize = Integer.parseInt(ConfigResolver.getPropertyValue("dw." + poolName + ".pool.normal.size", "50"));
    highPriorityPoolSize = Integer.parseInt(ConfigResolver.getPropertyValue("dw." + poolName + ".pool.high.size", "100"));
    adminPriorityPoolSize = Integer.parseInt(ConfigResolver.getPropertyValue("dw." + poolName + ".pool.admin.size", "200"));
}