eclipse-ee4j / jersey

Eclipse Jersey Project - Read our Wiki:
https://github.com/eclipse-ee4j/jersey/wiki
Other
692 stars 353 forks source link

JerseyTest: ServletDeploymentContext.addFilter() has no effect #3368

Open jerseyrobot opened 8 years ago

jerseyrobot commented 8 years ago

I have the following test class:

**MyTest.java**public class MyTest extends JerseyTest {
  @Override
  protected DeploymentContext configureDeployment() {
    return ServletDeploymentContext.builder(configure()).addFilter(SomeFilter.class, "SomeFilterName").build();
  }
}

Plus the following filter

**SomeFilter.java**public class SomeFilter implements Filter {
  public void init(FilterConfig filterConfig) {
  }
  public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
    filterChain.doFilter(servletRequest, servletResponse);
  }
  public void destroy() {
  }
}

If been looking through the code and couldn't find any place where the fitler I added would be read. I would have expected it to be read in GrizzlyTestContainerFactory#GrizzlyTestContainer, JettyTestContainerFactory#JettyTestContainer or InMemoryTestContainerFactory#InMemoryTestContainer.

Looks like this feature was not used so far and is not implemented yet.

Affected Versions

[2.22.1]

jerseyrobot commented 6 years ago
jerseyrobot commented 8 years ago

@glassfishrobot Commented Reported by egore911

jerseyrobot commented 8 years ago

@glassfishrobot Commented @pavelbucek said: What about GrizzlyWebServletAndFilterTest ?

In general, you can't use ServletDeploymentContext on non servlet containers. GrizzlyTestConatiner and InMemoryTest container are NOT servlet containers. The only one is GrizzlyWebTestContainer/GrizzlyWebTestContainerFactory..

jerseyrobot commented 8 years ago

@glassfishrobot Commented egore911 said: I added the following to my test:

protected TestContainerFactory getTestContainerFactory() {
    return new GrizzlyWebTestContainerFactory();
  }

This makes my code work. Thanks for the hints.

jerseyrobot commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA JERSEY-3096