Search in sources :

Example 1 with ServletRequestFilter

use of com.giffing.bucket4j.spring.boot.starter.servlet.ServletRequestFilter in project bucket4j-spring-boot-starter by MarcGiffing.

the class ServletRateLimitFilterTest method setup.

@Before
public void setup() {
    consumptionProbe = Mockito.mock(ConsumptionProbe.class);
    when(consumptionProbe.isConsumed()).thenReturn(true);
    rateLimitCheck1 = mock(RateLimitCheck.class);
    rateLimitCheck2 = mock(RateLimitCheck.class);
    rateLimitCheck3 = mock(RateLimitCheck.class);
    configuration = new FilterConfiguration();
    configuration.setRateLimitChecks(Arrays.asList(rateLimitCheck1, rateLimitCheck2, rateLimitCheck3));
    configuration.setUrl("url");
    filter = new ServletRequestFilter(configuration);
}
Also used : ServletRequestFilter(com.giffing.bucket4j.spring.boot.starter.servlet.ServletRequestFilter) RateLimitCheck(com.giffing.bucket4j.spring.boot.starter.context.RateLimitCheck) FilterConfiguration(com.giffing.bucket4j.spring.boot.starter.context.FilterConfiguration) ConsumptionProbe(io.github.bucket4j.ConsumptionProbe) Before(org.junit.Before)

Example 2 with ServletRequestFilter

use of com.giffing.bucket4j.spring.boot.starter.servlet.ServletRequestFilter in project bucket4j-spring-boot-starter by MarcGiffing.

the class Bucket4JAutoConfigurationServletFilter method getFilterRegistrationBean.

private FilterRegistrationBean getFilterRegistrationBean(int position) {
    Integer filterCount = 0;
    if (properties.getFilters().size() >= (position + 1)) {
        Bucket4JConfiguration filter = properties.getFilters().get(position);
        filterCount++;
        FilterConfiguration filterConfig = buildFilterConfig(filter, cacheManager, servletFilterExpressionParser(), beanFactory);
        servletConfigurationHolder().addFilterConfiguration(filter);
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setName("bucket4JRequestFilter" + position);
        registration.setFilter(new ServletRequestFilter(filterConfig));
        registration.addUrlPatterns(filter.getUrl());
        registration.setOrder(filter.getFilterOrder());
        log.info("create-servlet-filter;{};{};{}", position, filter.getCacheName(), filter.getUrl());
        return registration;
    }
    return null;
}
Also used : ServletRequestFilter(com.giffing.bucket4j.spring.boot.starter.servlet.ServletRequestFilter) Bucket4JConfiguration(com.giffing.bucket4j.spring.boot.starter.context.properties.Bucket4JConfiguration) FilterConfiguration(com.giffing.bucket4j.spring.boot.starter.context.FilterConfiguration) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean)

Aggregations

FilterConfiguration (com.giffing.bucket4j.spring.boot.starter.context.FilterConfiguration)2 ServletRequestFilter (com.giffing.bucket4j.spring.boot.starter.servlet.ServletRequestFilter)2 RateLimitCheck (com.giffing.bucket4j.spring.boot.starter.context.RateLimitCheck)1 Bucket4JConfiguration (com.giffing.bucket4j.spring.boot.starter.context.properties.Bucket4JConfiguration)1 ConsumptionProbe (io.github.bucket4j.ConsumptionProbe)1 Before (org.junit.Before)1 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)1