com.netflix.zuul.ZuulFilter Java Examples

The following examples show how to use com.netflix.zuul.ZuulFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ZuulTest.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyContextCleared(final MockTracer tracer) {
  final RequestContext context = RequestContext.getCurrentContext();
  final HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
  context.setRequest(httpServletRequest);
  Mockito.when(httpServletRequest.getMethod()).thenReturn("GET");

  final ZuulFilter preFilter = FilterLoader.getInstance().getFiltersByType("pre").get(0);
  preFilter.run();
  assertNotNull(context.get(TracePreZuulFilter.CONTEXT_SPAN_KEY));

  final ZuulFilter postFilter = FilterLoader.getInstance().getFiltersByType("post").get(0);
  postFilter.run();
  assertNull(context.get(TracePreZuulFilter.CONTEXT_SPAN_KEY));

  assertEquals(1, tracer.finishedSpans().size());
}
 
Example #2
Source File: ZuulTest.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
  final ZuulFilter preFilter = FilterLoader.getInstance().getFiltersByType("pre").get(0);
  assertTrue(preFilter instanceof TracePreZuulFilter);

  // verify we don't add pre filter continuously
  assertEquals(1, FilterLoader.getInstance().getFiltersByType("pre").size());
  assertEquals(1, FilterLoader.getInstance().getFiltersByType("pre").size());

  final ZuulFilter postFilter = FilterLoader.getInstance().getFiltersByType("post").get(0);
  assertTrue(postFilter instanceof TracePostZuulFilter);

  // verify we don't add post filter continuously
  assertEquals(1, FilterLoader.getInstance().getFiltersByType("post").size());
  assertEquals(1, FilterLoader.getInstance().getFiltersByType("post").size());
}
 
Example #3
Source File: ErrorFilter.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@Override
public Object processZuulFilter(ZuulFilter filter) throws ZuulException {
    try {
        return super.processZuulFilter(filter);
    } catch (ZuulException e) {
        RequestContext ctx = RequestContext.getCurrentContext();
        ctx.set(FAILED_FILTER, filter);
        throw e;
    }
}
 
Example #4
Source File: RateLimitAutoConfigurationTest.java    From spring-cloud-zuul-ratelimit with Apache License 2.0 5 votes vote down vote up
@Test
public void testZuulFilters() {
    contextRunner.withPropertyValues(PREFIX + ".repository=BUCKET4J_JCACHE")
            .run(context -> {
                assertThat(context).getBeanNames(ZuulFilter.class).hasSize(2);
                assertThat(context).getBeanNames(ZuulFilter.class)
                        .containsExactly("rateLimiterPreFilter", "rateLimiterPostFilter");
            });
}
 
Example #5
Source File: RateLimitAutoConfiguration.java    From spring-cloud-zuul-ratelimit with Apache License 2.0 5 votes vote down vote up
@Bean
public ZuulFilter rateLimiterPostFilter(final RateLimiter rateLimiter, final RateLimitProperties rateLimitProperties,
                                        final RouteLocator routeLocator, final RateLimitKeyGenerator rateLimitKeyGenerator,
                                        final RateLimitUtils rateLimitUtils) {
    return new RateLimitPostFilter(rateLimitProperties, routeLocator, URL_PATH_HELPER, rateLimiter,
            rateLimitKeyGenerator, rateLimitUtils);
}
 
Example #6
Source File: RateLimitAutoConfiguration.java    From spring-cloud-zuul-ratelimit with Apache License 2.0 5 votes vote down vote up
@Bean
public ZuulFilter rateLimiterPreFilter(final RateLimiter rateLimiter, final RateLimitProperties rateLimitProperties,
                                       final RouteLocator routeLocator, final RateLimitKeyGenerator rateLimitKeyGenerator,
                                       final RateLimitUtils rateLimitUtils, final ApplicationEventPublisher eventPublisher) {
    return new RateLimitPreFilter(rateLimitProperties, routeLocator, URL_PATH_HELPER, rateLimiter,
            rateLimitKeyGenerator, rateLimitUtils, eventPublisher);
}
 
Example #7
Source File: ErrorExtFilter.java    From xmfcn-spring-cloud with Apache License 2.0 5 votes vote down vote up
@Override
public boolean shouldFilter() {
    // 判断:仅处理来自post过滤器引起的异常
    RequestContext ctx = RequestContext.getCurrentContext();
    ZuulFilter failedFilter = (ZuulFilter) ctx.get("failed.filter");
    if (failedFilter != null && ("post".equals(failedFilter.filterType()) || "get".equals(failedFilter.filterType()))) {
        return true;
    }
    return true;
}
 
Example #8
Source File: GatewayConfiguration.java    From open-cloud with MIT License 5 votes vote down vote up
/**
 * 修改请求头
 *
 * @return
 */
@Bean
public ZuulFilter modifyHeaderFilter() {
    ZuulFilter zuulFilter = new ModifyHeaderFilter();
    log.info("ModifyHeaderFilter [{}]", zuulFilter);
    return zuulFilter;
}
 
Example #9
Source File: GatewayConfiguration.java    From open-cloud with MIT License 5 votes vote down vote up
/**
 * 错误过滤器
 *
 * @return
 */
@Bean
public ZuulFilter zuulErrorFilter() {
    ZuulFilter zuulFilter = new ZuulErrorFilter(accessLogService);
    log.info("ZuulErrorFilter [{}]", zuulFilter);
    return zuulFilter;
}
 
Example #10
Source File: GatewayConfiguration.java    From open-cloud with MIT License 5 votes vote down vote up
/**
 * 响应过滤器
 *
 * @return
 */
@Bean
public ZuulFilter zuulResponseFilter() {
    ZuulFilter zuulFilter = new ZuulResponseFilter(accessLogService);
    log.info("ZuulErrorFilter [{}]", zuulFilter);
    return zuulFilter;
}
 
Example #11
Source File: ErrorFilter.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@Override
public boolean shouldFilter() {
    // 判断:仅处理post过滤器引起的异常
    RequestContext ctx = RequestContext.getCurrentContext();
    ZuulFilter failedFilter = (ZuulFilter) ctx.get(FAILED_FILTER);
    return failedFilter != null && failedFilter.filterType().equals(FilterConstants.POST_TYPE);
}
 
Example #12
Source File: ZuulConfig.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
@Bean
public ZuulFilter sentinelZuulErrorFilter() {
    return new SentinelZuulErrorFilter(-1);
}
 
Example #13
Source File: ZuulAPIGatewayApplication.java    From Spring with Apache License 2.0 4 votes vote down vote up
@Bean
public ZuulFilter zuulFilter(){
    return new ORZuulFilter();
}
 
Example #14
Source File: AppConfiguration.java    From Spring with Apache License 2.0 4 votes vote down vote up
@Bean
public ZuulFilter zuulFilter(){
    return new AddRequestHeaderFilter();
}
 
Example #15
Source File: ZuulConfig.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
@Bean
public ZuulFilter sentinelZuulPostFilter() {
    return new SentinelZuulPostFilter(1000);
}
 
Example #16
Source File: ZuulConfig.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 4 votes vote down vote up
@Bean
public ZuulFilter sentinelZuulPreFilter() {
    return new SentinelZuulPreFilter(10000);
}
 
Example #17
Source File: ZuulConfig.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
@Bean
public ZuulFilter sentinelZuulPreFilter() {
    return new SentinelZuulPreFilter(10000);
}
 
Example #18
Source File: ZuulConfig.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
@Bean
public ZuulFilter sentinelZuulPostFilter() {
    return new SentinelZuulPostFilter(1000);
}
 
Example #19
Source File: ZuulConfig.java    From Sentinel with Apache License 2.0 4 votes vote down vote up
@Bean
public ZuulFilter sentinelZuulErrorFilter() {
    return new SentinelZuulErrorFilter(-1);
}
 
Example #20
Source File: ZuulConfiguration.java    From moserp with Apache License 2.0 4 votes vote down vote up
@Bean
public ZuulFilter urlRewritingFilter() {
    return new ContentUrlRewritingFilter();
}