public final class PersistFilter extends java.lang.Object implements Filter
PersistService
upon Filter.init(javax.servlet.FilterConfig)
and Filter.destroy()
respectively.
To be able to use the open session-in-view pattern (i.e. work per request), register this
filter once in your Guice ServletModule
. It is important that you register this
filter before any other filter.
For multiple providers, you should register this filter once per provider, inside a private module for each persist module installed (this must be the same private module where the specific persist module is itself installed).
Example configuration:
public class MyModule extends ServletModule {
public void configureServlets() {
filter("/*").through(PersistFilter.class);
serve("/index.html").with(MyHtmlServlet.class);
// Etc.
}
}
This filter is thread safe and allows you to create injectors concurrently and deploy multiple guice-persist modules within the same injector, or even multiple injectors with persist modules withing the same JVM or web app.
This filter requires the Guice Servlet extension.
Constructor and Description |
---|
PersistFilter(UnitOfWork unitOfWork,
PersistService persistService) |
Modifier and Type | Method and Description |
---|---|
void |
destroy() |
void |
doFilter(ServletRequest servletRequest,
ServletResponse servletResponse,
FilterChain filterChain) |
void |
init(FilterConfig filterConfig) |
@Inject public PersistFilter(UnitOfWork unitOfWork, PersistService persistService)
public void init(FilterConfig filterConfig) throws ServletException
init
in interface Filter
ServletException
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws java.io.IOException, ServletException
doFilter
in interface Filter
java.io.IOException
ServletException