Togglz console is giving 404 for springboot application

1,241 views
Skip to first unread message

Hema

unread,
Apr 22, 2016, 5:47:20 PM4/22/16
to togglz-users
Gradle dependencies:

compile('org.springframework.boot:spring-boot-starter-web')
compile 'org.togglz:togglz-servlet:2.0.1.Final'
compile("org.togglz:togglz-console:2.3.0.RC1")
    compile("org.togglz:togglz-spring-security:2.3.0.RC1")
    compile("com.github.heneke.thymeleaf:thymeleaf-extras-togglz:1.0.1.RELEASE") 
    compile('org.springframework.boot:spring-boot-starter-actuator')
    testCompile("org.togglz:togglz-junit:2.3.0.RC1")
testCompile('org.springframework.boot:spring-boot-starter-test') 
compile(group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.5')


Features enum:

/**
 * Sample features for this demo.
 */
public enum DemoFeature implements Feature
{

  @EnabledByDefault
  @Label("First Feature is enabled by default")
  FEATURE_ONE,

  @Label("Second Feature")
  FEATURE_TWO,

  @Label("Third Feature")
  FEATURE_THREE;

  public boolean isActive()
  {

    return FeatureManagerWrapper.getInstance().getFeatureManager().isActive(this);
  }
}


Application:


@EnableAutoConfiguration
@Configuration
@ComponentScan
public class StatusApplication
{

  public static void main(String[] args)
  {
    SpringApplication.run(StatusApplication.class, args);
  }

  @Bean
  public FeatureManagerWrapper featureManagerWrapper()
    throws IOException
  {
    final FeatureManagerBuilder builder = new FeatureManagerBuilder();
    builder.name("demo-feature-manager").featureEnum(DemoFeature.class).stateRepository(stateRepository())
           .userProvider(userProvider());
    final FeatureManager featureManager = builder.build();
    final FeatureManagerWrapper featureManagerWrapper = FeatureManagerWrapper.getInstance();
    featureManagerWrapper.setFeatureManager(featureManager);
    return featureManagerWrapper;
  }

  @Bean
  public StateRepository stateRepository()
    throws IOException
  {
    return new FileBasedStateRepository(new File("src/main/resources/application.properties"));
  }

  @Bean
  public UserProvider userProvider()
  {
    return new UserProvider()
    {
      @Override
      public FeatureUser getCurrentUser()
      {
        return new SimpleFeatureUser("admin", true);
      }
    };
  }
}

FeatureManagerWrapper:

public class FeatureManagerWrapper {
    private FeatureManager featureManager;
    private static final FeatureManagerWrapper instance = new FeatureManagerWrapper();

    private FeatureManagerWrapper() {
        // singleton
    }

    public static FeatureManagerWrapper getInstance() {
        return instance;
    }

    public void setFeatureManager(FeatureManager featureManager) {
        if(this.featureManager == null) {
            this.featureManager = featureManager;
        } else {
            throw new UnsupportedOperationException("featureManager is already set, cannot reset.");
        }
    }

    public FeatureManager getFeatureManager() {
        return featureManager;
    }
}


Application.properties:

togglz:
  enabled: true
  feature-enums: com.test.DemoFeature
  feature-manager-name:
  features:
    FEATURE_ONE: false
    FEATURE_TWO: true
    FEATURE_THREE: false
  features-file:                                         
  features-file-min-check-interval:
  cache:
    enabled: false
    time-to-live: 0
    time-unit: milliseconds
  console:
    enabled: true
    path: /togglz-console
    feature-admin-authority:
    secured: false
  endpoint:
    id: togglz
    enabled: true
    sensitive: true



When we hit "http://localhost:8080/togglz-console" just returns 404. Any help would be appreciated.

Christian Kaltepoth

unread,
Apr 23, 2016, 1:55:00 AM4/23/16
to togglz...@googlegroups.com
Could you explain why you created FeatureManagerWrapper? This looks weird to me. Not sure if this is perhaps causing your problems.

Your Feature.isActive() method should always be implemented like shown in the documentation.

Christian

Marcel Overdijk

unread,
Apr 23, 2016, 6:45:53 AM4/23/16
to togglz-users
Hi Hema,

Is this a public project you can share or isolate the problem in a smaller application published on github?
Like Christian mentioned can you explain the FeatureManagerWrapper?

I also don't quite understand your setup.
I think you are using Spring Security but then I wonder why you creating the userProvider bean manually?
Don't you want to use the actual Spring Security user?
In that case you can just remove the userProvider bean and let the auto configuration create a SpringSecurityUserProvider.
But then you have to set the feature-admin-authority application property.

You can read more about it at http://www.togglz.org/documentation/spring-boot-starter.html paragraph Admin Console Security.

If this doesn't help it might be a good idea to enable the Boot Actuator starter and see what auto configuration is happening.

Marcel

Hemalatha Konki

unread,
Apr 24, 2016, 6:27:33 PM4/24/16
to togglz...@googlegroups.com
Hi Christian & Marcel

Created a new sample project by exactly following documentation to show what's the issue I'm facing. You can clone it from https://github.com/hkonki/TogglzDemo.git.

Let me know if I have correct anything.

Thank you so much for quick response! Really appreciated.

Marcel Overdijk

unread,
Apr 25, 2016, 7:36:46 AM4/25/16
to togglz-users
Hi Hema,

Thanks for the separate TogglzDemo project.
There are quite a few things going wrong here :-)

  1. Your application.properties file contains yaml, so it should be named application.yml
  2. This configuration file contains feature-enums: com.example.Myfeatures which is a class that does not exist.. it should be com.example.MyFeatures (note the capital F) as this how you named your class.
  3. Note that your TogglzDemoApplication also contains an explicit featureProvider definition. This is not needed if you want to use the properties, otherwise just remove the feature-enums property form the configuration file.
  4. It also not clear what you are trying to with the MyTogglzConfiguration. This also contains another features provider. But also a FileBasedStateRepository pointing to application.properties. That can't be right. Probably you can remove this MyTogglzConfiguration completely.
Marcel

Hemalatha Konki

unread,
Apr 25, 2016, 10:22:22 AM4/25/16
to togglz...@googlegroups.com
Hi Marcel,

Thanks for clear explanation. I'm new to Spring boot as well as Togglz so I really appreciate your help.
Corrected all above things. Now can see togglz-console but few questions.

1. Console is directly representing enum(MYFeatures)? I thought it would read from applcation.yml. Which one takes priority?  what can we mention for 'feature-manager-name' in application.yml?
2. When we try to enable features from console it's giving error. Attached the exception.
3. When we try to enable or disable features where is it getting saved? application.yml??
4. My controller seems it's not reading from aplication.yml, what's the reason?

Thank you so much for your help on this and quick response!!

Exception.txt

Hemalatha Konki

unread,
Apr 25, 2016, 10:54:44 AM4/25/16
to togglz...@googlegroups.com
It looks like specifying file name for 'features-file: applcation.yml' in applcation.yml solved all the issue. But I would still look for your answers. Thank you!

Christian Kaltepoth

unread,
Apr 26, 2016, 3:40:02 AM4/26/16
to togglz...@googlegroups.com
Please not the "features-file" must refer to a Java properties file which will be used to store the feature state. So you will typically want use some external file here.

Marcel Overdijk

unread,
Apr 26, 2016, 9:07:56 AM4/26/16
to togglz-users
1. Console is directly representing enum(MYFeatures)? I thought it would read from applcation.yml. Which one takes priority?  what can we mention for 'feature-manager-name' in application.yml?

It's optional to provide a feature manager name. I think if you set it, it's name is displaued in the console.

2. When we try to enable features from console it's giving error. Attached the exception.
3. When we try to enable or disable features where is it getting saved? application.yml??

It depends on state repository used. See also http://www.togglz.org/documentation/repositories.html.

4. My controller seems it's not reading from aplication.yml, what's the reason?

I don't understand the question to be honest.

As Christian already pointed out the features-file should point to a Togglz features properties file (see ). not the application.yml. The latter one is your apps Spring Boot configuration file.
You either choose to define the feature values inside application.yaml and then they are kept in memory. But in that case you should not specify a features-file.
Reply all
Reply to author
Forward
0 new messages