Search in sources :

Example 1 with ServletFilter

use of org.sonar.api.web.ServletFilter in project sonarqube by SonarSource.

the class MasterServletFilter method initFilters.

public void initFilters(List<ServletFilter> filterExtensions) throws ServletException {
    List<ServletFilter> filterList = Lists.newArrayList();
    for (ServletFilter extension : filterExtensions) {
        try {
            Loggers.get(MasterServletFilter.class).info(String.format("Initializing servlet filter %s [pattern=%s]", extension, extension.doGetPattern()));
            extension.init(config);
            filterList.add(extension);
        } catch (Exception e) {
            throw new IllegalStateException("Fail to initialize servlet filter: " + extension + ". Message: " + e.getMessage(), e);
        }
    }
    filters = filterList.toArray(new ServletFilter[filterList.size()]);
}
Also used : ServletFilter(org.sonar.api.web.ServletFilter) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 2 with ServletFilter

use of org.sonar.api.web.ServletFilter in project sonarqube by SonarSource.

the class MasterServletFilterTest method should_init_and_destroy_filters.

@Test
public void should_init_and_destroy_filters() throws Exception {
    ServletFilter filter = mock(ServletFilter.class);
    FilterConfig config = mock(FilterConfig.class);
    MasterServletFilter master = new MasterServletFilter();
    master.init(config, singletonList(filter));
    assertThat(master.getFilters()).containsOnly(filter);
    verify(filter).init(config);
    master.destroy();
    verify(filter).destroy();
}
Also used : ServletFilter(org.sonar.api.web.ServletFilter) FilterConfig(javax.servlet.FilterConfig) Test(org.junit.Test)

Example 3 with ServletFilter

use of org.sonar.api.web.ServletFilter in project sonarqube by SonarSource.

the class MasterServletFilterTest method should_propagate_initialization_failure.

@Test
public void should_propagate_initialization_failure() throws Exception {
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("foo");
    ServletFilter filter = mock(ServletFilter.class);
    doThrow(new IllegalStateException("foo")).when(filter).init(any(FilterConfig.class));
    FilterConfig config = mock(FilterConfig.class);
    MasterServletFilter filters = new MasterServletFilter();
    filters.init(config, singletonList(filter));
}
Also used : ServletFilter(org.sonar.api.web.ServletFilter) FilterConfig(javax.servlet.FilterConfig) Test(org.junit.Test)

Example 4 with ServletFilter

use of org.sonar.api.web.ServletFilter in project sonarqube by SonarSource.

the class RegisterServletFiltersTest method should_not_fail_if_master_filter_is_not_up.

@Test
public void should_not_fail_if_master_filter_is_not_up() throws ServletException {
    MasterServletFilter.INSTANCE = null;
    new RegisterServletFilters(new ServletFilter[2]).start();
}
Also used : MasterServletFilter(org.sonar.server.platform.web.MasterServletFilter) ServletFilter(org.sonar.api.web.ServletFilter) RegisterServletFilters(org.sonar.server.platform.web.RegisterServletFilters) Test(org.junit.Test)

Example 5 with ServletFilter

use of org.sonar.api.web.ServletFilter in project sonarqube by SonarSource.

the class RegisterServletFiltersTest method should_register_filters_if_master_filter_is_up.

@Test
public void should_register_filters_if_master_filter_is_up() throws ServletException {
    MasterServletFilter.INSTANCE = mock(MasterServletFilter.class);
    new RegisterServletFilters(new ServletFilter[2]).start();
    verify(MasterServletFilter.INSTANCE).initFilters(anyListOf(ServletFilter.class));
}
Also used : MasterServletFilter(org.sonar.server.platform.web.MasterServletFilter) MasterServletFilter(org.sonar.server.platform.web.MasterServletFilter) ServletFilter(org.sonar.api.web.ServletFilter) RegisterServletFilters(org.sonar.server.platform.web.RegisterServletFilters) Test(org.junit.Test)

Aggregations

ServletFilter (org.sonar.api.web.ServletFilter)6 Test (org.junit.Test)4 FilterConfig (javax.servlet.FilterConfig)2 MasterServletFilter (org.sonar.server.platform.web.MasterServletFilter)2 RegisterServletFilters (org.sonar.server.platform.web.RegisterServletFilters)2 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1