Au is a filter framework. It is an extension based on servlet-filter. It provides pre-filtering and post-filtering of interceptor behavior. It also provides multiple reads of requests and a wrapper for response.
The architecture of Au as follows:
Au environment dependency as follow:
Au | Java | servlet-api |
---|---|---|
1.x | 1.8+ | javax.servlet-api:>=4.0.0 |
2.x | 1.8+ | jakarta.servlet-api:>=5.0.0 |
3.x | 17+ | jakarta.servlet-api:>=5.0.0 |
Complete example can view au-example
<dependency>
<groupId>com.lazycece.au</groupId>
<artifactId>au-core</artifactId>
<version>${au.core.version}</version>
</dependency>
Defining filter
,and implement the AuFilter
.
public class SimpleAuFilter implements AuFilter {
@Override
public String name() {
return "simple-filter";
}
@Override
public boolean preHandle() throws Exception {
// pre handle
return true;
}
@Override
public void postHandle() throws Exception {
// post-handle
}
}
Injecting AuFilter
,and you can also set related policies for filters.
AuManager auManager = AuManager.getInstance();
auManager.addAuFilter(SimpleAuFilter.class)
.excludePatterns("/a/b")
.includePatterns("/**")
.order(1);
auManager.setWrapper(true);
Injecting AuServletFilter
into Servlet
, as follow(jetty
):
ServletContextHandler contextHandler = new ServletContextHandler();
contextHandler.setContextPath("/au");
server.setHandler(contextHandler);
contextHandler.addServlet(ExampleServlet.class, "/*");
contextHandler.addFilter(AuServletFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));