Package com.google.inject.servlet
Class GuiceFilter
- java.lang.Object
-
- com.google.inject.servlet.GuiceFilter
-
- All Implemented Interfaces:
javax.servlet.Filter
public class GuiceFilter extends java.lang.Object implements javax.servlet.FilterApply this filter in web.xml above all other filters (typically), to all requests where you plan to use servlet scopes. This is also needed in order to dispatch requests to injectable filters and servlets:<filter> <filter-name>guiceFilter</filter-name> <filter-class>com.google.inject.servlet.GuiceFilter</filter-class> </filter> <filter-mapping> <filter-name>guiceFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>This filter must appear before every filter that makes use of Guice injection or servlet scopes functionality. Typically, you will only register this filter in web.xml and register any other filters (and servlets) using aServletModule.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classGuiceFilter.Context
-
Field Summary
Fields Modifier and Type Field Description private FilterPipelineinjectedPipelineWe allow both the static and dynamic versions of the pipeline to exist.(package private) static java.lang.ThreadLocal<GuiceFilter.Context>localContextprivate static java.util.logging.LoggerLOGGERprivate static java.lang.StringMULTIPLE_INJECTORS_WARNING(package private) static FilterPipelinepipeline(package private) static java.lang.ref.WeakReference<javax.servlet.ServletContext>servletContextUsed to inject the servlets configured viaServletModule
-
Constructor Summary
Constructors Constructor Description GuiceFilter()GuiceFilter(FilterPipeline filterPipeline)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddestroy()voiddoFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain)private static GuiceFilter.ContextgetContext(Key<?> key)private FilterPipelinegetFilterPipeline()(package private) static javax.servlet.http.HttpServletRequestgetOriginalRequest(Key<?> key)(package private) static javax.servlet.http.HttpServletRequestgetRequest(Key<?> key)(package private) static javax.servlet.http.HttpServletResponsegetResponse(Key<?> key)(package private) static javax.servlet.ServletContextgetServletContext()voidinit(javax.servlet.FilterConfig filterConfig)(package private) static voidreset()(package private) static voidsetPipeline(FilterPipeline pipeline)
-
-
-
Field Detail
-
localContext
static final java.lang.ThreadLocal<GuiceFilter.Context> localContext
-
pipeline
static volatile FilterPipeline pipeline
-
injectedPipeline
private final FilterPipeline injectedPipeline
We allow both the static and dynamic versions of the pipeline to exist.
-
servletContext
static volatile java.lang.ref.WeakReference<javax.servlet.ServletContext> servletContext
Used to inject the servlets configured viaServletModule
-
MULTIPLE_INJECTORS_WARNING
private static final java.lang.String MULTIPLE_INJECTORS_WARNING
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
-
Constructor Detail
-
GuiceFilter
public GuiceFilter()
-
GuiceFilter
@Inject GuiceFilter(FilterPipeline filterPipeline)
-
-
Method Detail
-
setPipeline
@Inject static void setPipeline(FilterPipeline pipeline)
-
reset
static void reset()
-
doFilter
public void doFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain) throws java.io.IOException, javax.servlet.ServletException- Specified by:
doFilterin interfacejavax.servlet.Filter- Throws:
java.io.IOExceptionjavax.servlet.ServletException
-
getOriginalRequest
static javax.servlet.http.HttpServletRequest getOriginalRequest(Key<?> key)
-
getRequest
static javax.servlet.http.HttpServletRequest getRequest(Key<?> key)
-
getResponse
static javax.servlet.http.HttpServletResponse getResponse(Key<?> key)
-
getServletContext
static javax.servlet.ServletContext getServletContext()
-
getContext
private static GuiceFilter.Context getContext(Key<?> key)
-
init
public void init(javax.servlet.FilterConfig filterConfig) throws javax.servlet.ServletException- Specified by:
initin interfacejavax.servlet.Filter- Throws:
javax.servlet.ServletException
-
destroy
public void destroy()
- Specified by:
destroyin interfacejavax.servlet.Filter
-
getFilterPipeline
private FilterPipeline getFilterPipeline()
-
-