Servlet Tools provides helper filters and listeners to make it easier to use Servlet annotations.
A project may have existing Servlet filters/listeners or 3rd party filters/listeners that are not annotated.
If the project is not using a web.xml and relying on Servlet annotations, the Servlet Tools combo filter/listener makes it easier for projects to combine these filters/listeners into a single class that can be annotated.
Without Servlet Tools the project would need to (1) define each filter/listener in a web.xml or (2) extend the existing filters/listeners and annotate the new classes.
Add dependency:
<project>
....
<dependency>
<groupId>com.github.bordertech.taskmaster</groupId>
<artifactId>java-servlet-tools</artifactId>
<version>1.0.0</version>
</dependency>
....
</project>
How to create a combo filter that combines multiple servlet filters into one annotated class:
- Create a new class that extends AbstractComboFilter
- In the constructor, define the filter classes to be combined
- Annotate the new class with @WebFilter
@WebFilter
public class MyFilter extends AbstractComboFilter {
public MyFilter() {
super(new ExistingFilter(), new AnotherFilter());
}
}
How to create a combo listener that combines multiple servlet listeners into one annotated class:
- Create a new class that extends AbstractComboServletListener
- In the constructor, define the listener classes to be combined
- Annotate the new class with @WebListener
@WebListener
public class MyListener extends AbstractComboServletListener {
public MyListener() {
super(new ExistingListener(), new AnotherListener());
}
}