3

I am trying to find if it is possible to use togglz in non web application - like we have plain java project or java batch programs.

I tried adding the togglz library in the stand alone application and tried running it.

this is my code snippet -

import com.feature.MyFeature;

public class Test {

    public static void main(String[] args) {

        Test t = new Test();
        boolean valid=t.validate("CREATE_TEAM");
        System.out.println(valid);

    }

    public boolean validate(String feature){

        if (MyFeature.valueOf(feature).isActive()) {
        return true;
        }

        return false;
    }

}

It says -

Exception in thread "main" java.lang.IllegalStateException: Could not find the FeatureManager. For web applications please verify that the TogglzFilter starts up correctly. In other deployment scenarios you will typically have to implement a FeatureManagerProvider as described in the 'Advanced Configuration' chapter of the documentation.
    at com.amdocs.switchlite.core.context.FeatureContext.getFeatureManager(FeatureContext.java:53)
    at com.feature.MyFeature.isActive(MyFeature.java:20)
    at Test.validate(Test.java:22)
    at Test.main(Test.java:12)
Ashish Shetkar
  • 1,414
  • 2
  • 18
  • 35
  • Can we see your pom.xml if any? What are the dependencies used? Can we also see your togglz config. –  Feb 17 '17 at 12:00

1 Answers1

4

You will have to configure Togglz correctly to make it work. In a standalone application I recommend the following setup.

First create a FeatureManager using the FeatureManagerBuilder. Something like this:

FeatureManager featureManager = FeatureManagerBuilder.begin()
        .featureEnum(Features.class)
        .stateRepository(new InMemoryStateRepository())
        .userProvider(new NoOpUserProvider())
        .build();

The tell StaticFeatureManagerProvider about your manager:

StaticFeatureManagerProvider.setFeatureManager(featureManager);

Now StaticFeatureManagerProvider is able to tell Togglz about your FeatureManager and everything should work fine!

Features.FOOBAR.isActive();
// > false
chkal
  • 5,598
  • 21
  • 26