javaee / jersey

This is no longer the active Jersey repository. Please see the README.md
http://jersey.github.io
Other
2.86k stars 2.35k forks source link

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

Open glassfishrobot opened 8 years ago

glassfishrobot 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]

glassfishrobot commented 8 years ago

Reported by egore911

glassfishrobot commented 8 years ago

@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..

glassfishrobot commented 8 years ago

egore911 said: I added the following to my test:

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

This makes my code work. Thanks for the hints.

glassfishrobot commented 7 years ago

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