use of com.netflix.zuul.ZuulFilter in project zuul by Netflix.
the class FilterVerifier method verifyFilter.
/**
* verifies compilation, instanciation and that it is a ZuulFilter
*
* @param sFilterCode
* @return a FilterInfo object representing that code
* @throws CompilationFailedException
*
* @throws IllegalAccessException
* @throws InstantiationException
*/
public FilterInfo verifyFilter(String sFilterCode) throws CompilationFailedException, IllegalAccessException, InstantiationException {
Class groovyClass = compileGroovy(sFilterCode);
Object instance = instanciateClass(groovyClass);
checkZuulFilterInstance(instance);
ZuulFilter filter = (ZuulFilter) instance;
return new FilterInfo(sFilterCode, groovyClass.getSimpleName(), filter);
}
use of com.netflix.zuul.ZuulFilter in project spring-cloud-netflix by spring-cloud.
the class CanaryTestRibbonClientConfiguration method testCanarySupportPreFilter.
@Bean
public ZuulFilter testCanarySupportPreFilter() {
return new ZuulFilter() {
@Override
public Object run() {
RequestContext context = RequestContext.getCurrentContext();
if (checkIfCanaryRequest(context)) {
// set loadBalancerKey for IRule
context.set(LOAD_BALANCER_KEY, "canary");
}
return null;
}
private boolean checkIfCanaryRequest(RequestContext context) {
HttpServletRequest request = context.getRequest();
// user defined header
String canaryHeader = request.getHeader("X-Canary-Test");
if ((canaryHeader != null) && (canaryHeader.equalsIgnoreCase("true"))) {
return true;
}
return false;
}
@Override
public boolean shouldFilter() {
return true;
}
@Override
public String filterType() {
return PRE_TYPE;
}
@Override
public int filterOrder() {
return 0;
}
};
}
use of com.netflix.zuul.ZuulFilter in project spring-cloud-netflix by spring-cloud.
the class FiltersEndpoint method invoke.
@ReadOperation
public Map<String, List<Map<String, Object>>> invoke() {
// Map of filters by type
final Map<String, List<Map<String, Object>>> filterMap = new TreeMap<>();
for (ZuulFilter filter : this.filterRegistry.getAllFilters()) {
// Ensure that we have a list to store filters of each type
if (!filterMap.containsKey(filter.filterType())) {
filterMap.put(filter.filterType(), new ArrayList<>());
}
final Map<String, Object> filterInfo = new LinkedHashMap<>();
filterInfo.put("class", filter.getClass().getName());
filterInfo.put("order", filter.filterOrder());
filterInfo.put("disabled", filter.isFilterDisabled());
filterInfo.put("static", filter.isStaticFilter());
filterMap.get(filter.filterType()).add(filterInfo);
}
return filterMap;
}
Aggregations