modify feature toggle
This commit is contained in:
parent
9eef07c494
commit
21295e67da
|
@ -186,12 +186,6 @@
|
|||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.togglz</groupId>
|
||||
<artifactId>togglz-spring</artifactId>
|
||||
<version>2.1.0.Final</version>
|
||||
</dependency>
|
||||
|
||||
<!-- logging -->
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
package org.baeldung.config;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.baeldung.reddit.util.MyFeatures;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.togglz.core.Feature;
|
||||
import org.togglz.core.manager.TogglzConfig;
|
||||
import org.togglz.core.repository.StateRepository;
|
||||
import org.togglz.core.repository.file.FileBasedStateRepository;
|
||||
import org.togglz.core.user.UserProvider;
|
||||
|
||||
@Configuration
|
||||
public class FeatureToggleConfig implements TogglzConfig {
|
||||
|
||||
@Override
|
||||
public Class<? extends Feature> getFeatureClass() {
|
||||
return MyFeatures.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StateRepository getStateRepository() {
|
||||
try {
|
||||
return new FileBasedStateRepository(new ClassPathResource("features.properties").getFile());
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserProvider getUserProvider() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -13,7 +13,7 @@ public class ServletInitializer extends AbstractDispatcherServletInitializer {
|
|||
@Override
|
||||
protected WebApplicationContext createServletApplicationContext() {
|
||||
final AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
||||
context.register(PersistenceJPAConfig.class, WebConfig.class, SecurityConfig.class, FeatureToggleConfig.class);
|
||||
context.register(PersistenceJPAConfig.class, WebConfig.class, SecurityConfig.class);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,6 @@ public class ServletInitializer extends AbstractDispatcherServletInitializer {
|
|||
@Override
|
||||
public void onStartup(ServletContext servletContext) throws ServletException {
|
||||
super.onStartup(servletContext);
|
||||
|
||||
servletContext.addListener(new SessionListener());
|
||||
registerProxyFilter(servletContext, "oauth2ClientContextFilter");
|
||||
registerProxyFilter(servletContext, "springSecurityFilterChain");
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.baeldung.config;
|
|||
import javax.servlet.http.HttpSessionEvent;
|
||||
import javax.servlet.http.HttpSessionListener;
|
||||
|
||||
import org.baeldung.reddit.util.MyFeatures;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -13,6 +14,7 @@ public class SessionListener implements HttpSessionListener {
|
|||
public void sessionCreated(HttpSessionEvent event) {
|
||||
logger.info("==== Session is created ====");
|
||||
event.getSession().setMaxInactiveInterval(30 * 60);
|
||||
event.getSession().setAttribute("PREDICTION_FEATURE", MyFeatures.PREDICTION_FEATURE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
package org.baeldung.reddit.util;
|
||||
|
||||
import org.togglz.core.Feature;
|
||||
import org.togglz.core.annotation.EnabledByDefault;
|
||||
import org.togglz.core.annotation.Label;
|
||||
import org.togglz.core.context.FeatureContext;
|
||||
public enum MyFeatures {
|
||||
|
||||
public enum MyFeatures implements Feature {
|
||||
PREDICTION_FEATURE(false);
|
||||
|
||||
@EnabledByDefault
|
||||
@Label("Prediction feature")
|
||||
PREDICTION_FEATURE;
|
||||
private boolean active;
|
||||
|
||||
private MyFeatures(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return FeatureContext.getFeatureManager().isActive(this);
|
||||
return this.active;
|
||||
}
|
||||
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
PREDICTION_FEATURE=false
|
|
@ -80,7 +80,7 @@ border-color: #ddd;
|
|||
</div>
|
||||
</form>
|
||||
<div>
|
||||
<c:if test="MyFeatures.PREDICTION_FEATURE.isActive()">
|
||||
<c:if test="${PREDICTION_FEATURE.isActive()}">
|
||||
<button id="checkbtn" class="btn btn-default disabled" onclick="predicateResponse()">Predicate Response</button>
|
||||
<span id="prediction"></span>
|
||||
|
||||
|
|
Loading…
Reference in New Issue