Java Code Examples for com.netflix.zuul.ZuulFilter

The following are top voted examples for showing how to use com.netflix.zuul.ZuulFilter. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: bucket4j-spring-boot-starter   File: Bucket4JAutoConfigurationZuul.java   View source code 7 votes vote down vote up
private ZuulFilter createZuulFilter(int position) {
	Integer filterCount = 0;
	if(properties.getFilters().size() >= (position+1)) {
		Bucket4JConfiguration filter = properties.getFilters().get(position);
		filterCount++;
		
		FilterConfiguration filterConfig = buildFilterConfig(filter, cacheManager, zuulExpressionParser(), beanFactory);
		
        return new ZuulRateLimitFilter(filterConfig);
	}
	
	return null;
}
 
Example 2
Project: spring-cloud-netflix   File: FiltersEndpoint.java   View source code 6 votes vote down vote up
@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;
}
 
Example 3
Project: spring-cloud-netflix   File: RetryableZuulProxyApplicationTests.java   View source code 6 votes vote down vote up
@Bean
public ZuulFilter sampleFilter() {
	return new ZuulFilter() {
		@Override
		public String filterType() {
			return PRE_TYPE;
		}

		@Override
		public boolean shouldFilter() {
			return true;
		}

		@Override
		public Object run() {
			return null;
		}

		@Override
		public int filterOrder() {
			return 0;
		}
	};
}
 
Example 4
Project: spring-cloud-netflix   File: FormZuulProxyApplicationTests.java   View source code 6 votes vote down vote up
@Bean
public ZuulFilter sampleFilter() {
	return new ZuulFilter() {

		@Override
		public String filterType() {
			return PRE_TYPE;
		}

		@Override
		public boolean shouldFilter() {
			return true;
		}

		@Override
		public Object run() {
			return null;
		}

		@Override
		public int filterOrder() {
			return 0;
		}

	};
}
 
Example 5
Project: spring-cloud-netflix   File: FormZuulServletProxyApplicationTests.java   View source code 6 votes vote down vote up
@Bean
public ZuulFilter sampleFilter() {
	return new ZuulFilter() {

		@Override
		public String filterType() {
			return PRE_TYPE;
		}

		@Override
		public boolean shouldFilter() {
			return true;
		}

		@Override
		public Object run() {
			return null;
		}

		@Override
		public int filterOrder() {
			return 0;
		}

	};
}
 
Example 6
Project: spring-cloud-netflix   File: SimpleZuulServerApplicationTests.java   View source code 6 votes vote down vote up
@Bean
public ZuulFilter sampleFilter() {
	return new ZuulFilter() {
		@Override
		public String filterType() {
			return PRE_TYPE;
		}

		@Override
		public boolean shouldFilter() {
			return true;
		}

		@Override
		public Object run() {
			return null;
		}

		@Override
		public int filterOrder() {
			return 0;
		}
	};
}
 
Example 7
Project: spring-cloud-zuul-ratelimit   File: RateLimitAutoConfiguration.java   View source code 5 votes vote down vote up
@Bean
public ZuulFilter rateLimiterPreFilter(final RateLimiter rateLimiter,
                                       final RateLimitProperties rateLimitProperties,
                                       final RouteLocator routeLocator,
                                       final RateLimitKeyGenerator rateLimitKeyGenerator) {
    return new RateLimitPreFilter(rateLimitProperties, routeLocator, urlPathHelper, rateLimiter,
            rateLimitKeyGenerator);
}
 
Example 8
Project: spring-cloud-zuul-ratelimit   File: RateLimitAutoConfiguration.java   View source code 5 votes vote down vote up
@Bean
public ZuulFilter rateLimiterPostFilter(final RateLimiter rateLimiter,
                                        final RateLimitProperties rateLimitProperties,
                                        final RouteLocator routeLocator,
                                        final RateLimitKeyGenerator rateLimitKeyGenerator) {
    return new RateLimitPostFilter(rateLimitProperties, routeLocator, urlPathHelper, rateLimiter,
            rateLimitKeyGenerator);
}
 
Example 9
Project: spring-cloud-zuul-ratelimit   File: RateLimitAutoConfigurationTest.java   View source code 5 votes vote down vote up
@Test
public void testZuulFilters() {
    this.context.refresh();

    Map<String, ZuulFilter> zuulFilterMap = context.getBeansOfType(ZuulFilter.class);
    assertThat(zuulFilterMap.size()).isEqualTo(2);
    assertThat(zuulFilterMap.keySet()).containsExactly("rateLimiterPreFilter", "rateLimiterPostFilter");
}
 
Example 10
Project: spring-cloud-netflix   File: ZuulFilterInitializer.java   View source code 5 votes vote down vote up
public ZuulFilterInitializer(Map<String, ZuulFilter> filters,
							 CounterFactory counterFactory,
							 TracerFactory tracerFactory,
							 FilterLoader filterLoader,
							 FilterRegistry filterRegistry) {
	this.filters = filters;
	this.counterFactory = counterFactory;
	this.tracerFactory = tracerFactory;
	this.filterLoader = filterLoader;
	this.filterRegistry = filterRegistry;
}
 
Example 11
Project: spring-cloud-netflix   File: ZuulFilterInitializer.java   View source code 5 votes vote down vote up
@PostConstruct
public void contextInitialized() {
	log.info("Starting filter initializer");

	TracerFactory.initialize(tracerFactory);
	CounterFactory.initialize(counterFactory);

	for (Map.Entry<String, ZuulFilter> entry : this.filters.entrySet()) {
		filterRegistry.put(entry.getKey(), entry.getValue());
	}
}
 
Example 12
Project: spring-cloud-netflix   File: ZuulFilterInitializer.java   View source code 5 votes vote down vote up
@PreDestroy
public void contextDestroyed() {
	log.info("Stopping filter initializer");
	for (Map.Entry<String, ZuulFilter> entry : this.filters.entrySet()) {
		filterRegistry.remove(entry.getKey());
	}
	clearLoaderCache();

	TracerFactory.initialize(null);
	CounterFactory.initialize(null);
}
 
Example 13
Project: spring-cloud-netflix   File: SendErrorFilterIntegrationTests.java   View source code 5 votes vote down vote up
@Bean
public ZuulFilter testPreFilter() {
	return new FailureFilter() {
		@Override
		public String filterType() {
			return PRE_TYPE;
		}
	};
}
 
Example 14
Project: spring-cloud-netflix   File: SendErrorFilterIntegrationTests.java   View source code 5 votes vote down vote up
@Bean
public ZuulFilter testRouteFilter() {
	return new FailureFilter() {
		@Override
		public String filterType() {
			return ROUTE_TYPE;
		}
	};
}
 
Example 15
Project: spring-cloud-netflix   File: SendErrorFilterIntegrationTests.java   View source code 5 votes vote down vote up
@Bean
public ZuulFilter testPostFilter() {
	return new FailureFilter() {
		@Override
		public String filterType() {
			return POST_TYPE;
		}
	};
}
 
Example 16
Project: spring-cloud-netflix   File: ZuulProxyTestBase.java   View source code 5 votes vote down vote up
@Bean
public ZuulFilter sampleFilter() {
	return new ZuulFilter() {
		@Override
		public String filterType() {
			return PRE_TYPE;
		}

		@Override
		public boolean shouldFilter() {
			return true;
		}

		@Override
		public Object run() {
			if (RequestContext.getCurrentContext().getRequest().getParameterMap()
					.containsKey("override")) {
				Map<String, List<String>> overridden = new HashMap<>();
				overridden.put("key", Arrays.asList("overridden"));
				RequestContext.getCurrentContext()
						.setRequestQueryParams(overridden);
			}
			return null;
		}

		@Override
		public int filterOrder() {
			return 0;
		}
	};

}
 
Example 17
Project: bucket4j-spring-boot-starter   File: Bucket4JAutoConfigurationZuul.java   View source code 4 votes vote down vote up
@Bean
@Conditional(ConfigCondition1.class)
public ZuulFilter zuulFilter1() {
	return createZuulFilter(0);
}
 
Example 18
Project: bucket4j-spring-boot-starter   File: Bucket4JAutoConfigurationZuul.java   View source code 4 votes vote down vote up
@Bean
@Conditional(ConfigCondition2.class)
public ZuulFilter zuulFilter2() {
	return createZuulFilter(1);
}
 
Example 19
Project: bucket4j-spring-boot-starter   File: Bucket4JAutoConfigurationZuul.java   View source code 4 votes vote down vote up
@Bean
@Conditional(ConfigCondition3.class)
public ZuulFilter zuulFilter3() {
	return createZuulFilter(2);
}
 
Example 20
Project: bucket4j-spring-boot-starter   File: Bucket4JAutoConfigurationZuul.java   View source code 4 votes vote down vote up
@Bean
@Conditional(ConfigCondition4.class)
public ZuulFilter zuulFilter4() {
	return createZuulFilter(3);
}
 
Example 21
Project: bucket4j-spring-boot-starter   File: Bucket4JAutoConfigurationZuul.java   View source code 4 votes vote down vote up
@Bean
@Conditional(ConfigCondition5.class)
public ZuulFilter zuulFilter5() {
	return createZuulFilter(4);
}
 
Example 22
Project: bucket4j-spring-boot-starter   File: Bucket4JAutoConfigurationZuul.java   View source code 4 votes vote down vote up
@Bean
@Conditional(ConfigCondition6.class)
public ZuulFilter zuulFilter6() {
	return createZuulFilter(5);
}
 
Example 23
Project: bucket4j-spring-boot-starter   File: Bucket4JAutoConfigurationZuul.java   View source code 4 votes vote down vote up
@Bean
@Conditional(ConfigCondition7.class)
public ZuulFilter zuulFilter7() {
	return createZuulFilter(6);
}
 
Example 24
Project: bucket4j-spring-boot-starter   File: Bucket4JAutoConfigurationZuul.java   View source code 4 votes vote down vote up
@Bean
@Conditional(ConfigCondition8.class)
public ZuulFilter zuulFilter8() {
	return createZuulFilter(7);
}
 
Example 25
Project: bucket4j-spring-boot-starter   File: Bucket4JAutoConfigurationZuul.java   View source code 4 votes vote down vote up
@Bean
@Conditional(ConfigCondition9.class)
public ZuulFilter zuulFilter9() {
	return createZuulFilter(8);
}
 
Example 26
Project: bucket4j-spring-boot-starter   File: Bucket4JAutoConfigurationZuul.java   View source code 4 votes vote down vote up
@Bean
@Conditional(ConfigCondition10.class)
public ZuulFilter zuulFilter10() {
	return createZuulFilter(9);
}
 
Example 27
Project: moserp   File: ZuulConfiguration.java   View source code 4 votes vote down vote up
@Bean
public ZuulFilter urlRewritingFilter() {
    return new ContentUrlRewritingFilter();
}
 
Example 28
Project: spring-cloud-netflix   File: FiltersEndpointTests.java   View source code 4 votes vote down vote up
@Bean
public ZuulFilter sampleFilter() {
	return new TestFilter();
}
 
Example 29
Project: spring-cloud-netflix   File: ZuulFilterInitializerTests.java   View source code 4 votes vote down vote up
private Map<String, ZuulFilter> getFilters() {
	Map<String, ZuulFilter> filters = new HashMap<>();
	filters.put("key1", mock(ZuulFilter.class));
	filters.put("key2", mock(ZuulFilter.class));
	return filters;
}