modify feature toggle
This commit is contained in:
parent
9eef07c494
commit
21295e67da
@ -186,12 +186,6 @@
|
|||||||
<version>${guava.version}</version>
|
<version>${guava.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.togglz</groupId>
|
|
||||||
<artifactId>togglz-spring</artifactId>
|
|
||||||
<version>2.1.0.Final</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- logging -->
|
<!-- logging -->
|
||||||
|
|
||||||
<dependency>
|
<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
|
@Override
|
||||||
protected WebApplicationContext createServletApplicationContext() {
|
protected WebApplicationContext createServletApplicationContext() {
|
||||||
final AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
|
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;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,7 +30,6 @@ public class ServletInitializer extends AbstractDispatcherServletInitializer {
|
|||||||
@Override
|
@Override
|
||||||
public void onStartup(ServletContext servletContext) throws ServletException {
|
public void onStartup(ServletContext servletContext) throws ServletException {
|
||||||
super.onStartup(servletContext);
|
super.onStartup(servletContext);
|
||||||
|
|
||||||
servletContext.addListener(new SessionListener());
|
servletContext.addListener(new SessionListener());
|
||||||
registerProxyFilter(servletContext, "oauth2ClientContextFilter");
|
registerProxyFilter(servletContext, "oauth2ClientContextFilter");
|
||||||
registerProxyFilter(servletContext, "springSecurityFilterChain");
|
registerProxyFilter(servletContext, "springSecurityFilterChain");
|
||||||
|
@ -3,6 +3,7 @@ package org.baeldung.config;
|
|||||||
import javax.servlet.http.HttpSessionEvent;
|
import javax.servlet.http.HttpSessionEvent;
|
||||||
import javax.servlet.http.HttpSessionListener;
|
import javax.servlet.http.HttpSessionListener;
|
||||||
|
|
||||||
|
import org.baeldung.reddit.util.MyFeatures;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -13,6 +14,7 @@ public class SessionListener implements HttpSessionListener {
|
|||||||
public void sessionCreated(HttpSessionEvent event) {
|
public void sessionCreated(HttpSessionEvent event) {
|
||||||
logger.info("==== Session is created ====");
|
logger.info("==== Session is created ====");
|
||||||
event.getSession().setMaxInactiveInterval(30 * 60);
|
event.getSession().setMaxInactiveInterval(30 * 60);
|
||||||
|
event.getSession().setAttribute("PREDICTION_FEATURE", MyFeatures.PREDICTION_FEATURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
package org.baeldung.reddit.util;
|
package org.baeldung.reddit.util;
|
||||||
|
|
||||||
import org.togglz.core.Feature;
|
public enum MyFeatures {
|
||||||
import org.togglz.core.annotation.EnabledByDefault;
|
|
||||||
import org.togglz.core.annotation.Label;
|
|
||||||
import org.togglz.core.context.FeatureContext;
|
|
||||||
|
|
||||||
public enum MyFeatures implements Feature {
|
PREDICTION_FEATURE(false);
|
||||||
|
|
||||||
@EnabledByDefault
|
private boolean active;
|
||||||
@Label("Prediction feature")
|
|
||||||
PREDICTION_FEATURE;
|
private MyFeatures(boolean active) {
|
||||||
|
this.active = active;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isActive() {
|
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>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<div>
|
<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>
|
<button id="checkbtn" class="btn btn-default disabled" onclick="predicateResponse()">Predicate Response</button>
|
||||||
<span id="prediction"></span>
|
<span id="prediction"></span>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user