Search in sources :

Example 1 with ZuulFilter

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);
}
Also used : ZuulFilter(com.netflix.zuul.ZuulFilter)

Example 2 with ZuulFilter

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;
        }
    };
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ZuulFilter(com.netflix.zuul.ZuulFilter) RequestContext(com.netflix.zuul.context.RequestContext) Bean(org.springframework.context.annotation.Bean)

Example 3 with ZuulFilter

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;
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) ZuulFilter(com.netflix.zuul.ZuulFilter) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation)

Aggregations

ZuulFilter (com.netflix.zuul.ZuulFilter)3 RequestContext (com.netflix.zuul.context.RequestContext)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 ReadOperation (org.springframework.boot.actuate.endpoint.annotation.ReadOperation)1 Bean (org.springframework.context.annotation.Bean)1