Package com.google.inject.servlet
Class ServletDefinition
- java.lang.Object
-
- com.google.inject.servlet.ServletDefinition
-
- All Implemented Interfaces:
Provider<ServletDefinition>,ProviderWithExtensionVisitor<ServletDefinition>,javax.inject.Provider<ServletDefinition>
class ServletDefinition extends java.lang.Object implements ProviderWithExtensionVisitor<ServletDefinition>
An internal representation of a servlet definition mapped to a particular URI pattern. Also performs the request dispatch to that servlet. How nice and OO =)
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicReference<javax.servlet.http.HttpServlet>httpServletprivate java.util.Map<java.lang.String,java.lang.String>initParamsprivate UriPatternMatcherpatternMatcherprivate javax.servlet.http.HttpServletservletInstanceprivate Key<? extends javax.servlet.http.HttpServlet>servletKey
-
Constructor Summary
Constructors Constructor Description ServletDefinition(Key<? extends javax.servlet.http.HttpServlet> servletKey, UriPatternMatcher patternMatcher, java.util.Map<java.lang.String,java.lang.String> initParams, javax.servlet.http.HttpServlet servletInstance)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <B,V>
VacceptExtensionVisitor(BindingTargetVisitor<B,V> visitor, ProviderInstanceBinding<? extends B> binding)Instructs the extension determine if the visitor is an instance of a custom extension visitor, and if so, visit it using that method.voiddestroy(java.util.Set<javax.servlet.http.HttpServlet> destroyedSoFar)(package private) voiddoService(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse)Utility that delegates to the actual service method of the servlet wrapped with a contextual request (i.e.private voiddoServiceImpl(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)ServletDefinitionget()Provides an instance ofT.(package private) java.lang.StringgetKey()voidinit(javax.servlet.ServletContext servletContext, Injector injector, java.util.Set<javax.servlet.http.HttpServlet> initializedSoFar)booleanservice(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse)Wrapper around the service chain to ensure a servlet is servicing what it must and provides it with a wrapped request.(package private) booleanshouldServe(java.lang.String uri)
-
-
-
Field Detail
-
servletKey
private final Key<? extends javax.servlet.http.HttpServlet> servletKey
-
patternMatcher
private final UriPatternMatcher patternMatcher
-
initParams
private final java.util.Map<java.lang.String,java.lang.String> initParams
-
servletInstance
private final javax.servlet.http.HttpServlet servletInstance
-
httpServlet
private final java.util.concurrent.atomic.AtomicReference<javax.servlet.http.HttpServlet> httpServlet
-
-
Constructor Detail
-
ServletDefinition
public ServletDefinition(Key<? extends javax.servlet.http.HttpServlet> servletKey, UriPatternMatcher patternMatcher, java.util.Map<java.lang.String,java.lang.String> initParams, javax.servlet.http.HttpServlet servletInstance)
-
-
Method Detail
-
get
public ServletDefinition get()
Description copied from interface:ProviderProvides an instance ofT.- Specified by:
getin interfaceProvider<ServletDefinition>- Specified by:
getin interfacejavax.inject.Provider<ServletDefinition>
-
acceptExtensionVisitor
public <B,V> V acceptExtensionVisitor(BindingTargetVisitor<B,V> visitor, ProviderInstanceBinding<? extends B> binding)
Description copied from interface:ProviderWithExtensionVisitorInstructs the extension determine if the visitor is an instance of a custom extension visitor, and if so, visit it using that method. If the visitor is not an instance of the custom extension visitor, this method MUST call visitor.visit(binding).Due to issues with generics, the type parameters of this method do not relate to the type of the provider. In practice, the 'B' type will always be a supertype of 'T'.
- Specified by:
acceptExtensionVisitorin interfaceProviderWithExtensionVisitor<ServletDefinition>
-
shouldServe
boolean shouldServe(java.lang.String uri)
-
init
public void init(javax.servlet.ServletContext servletContext, Injector injector, java.util.Set<javax.servlet.http.HttpServlet> initializedSoFar) throws javax.servlet.ServletException- Throws:
javax.servlet.ServletException
-
destroy
public void destroy(java.util.Set<javax.servlet.http.HttpServlet> destroyedSoFar)
-
service
public boolean service(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse) throws java.io.IOException, javax.servlet.ServletExceptionWrapper around the service chain to ensure a servlet is servicing what it must and provides it with a wrapped request.- Returns:
- Returns true if this servlet triggered for the given request. Or false if guice-servlet should continue dispatching down the servlet pipeline.
- Throws:
java.io.IOException- If thrown by underlying servletjavax.servlet.ServletException- If thrown by underlying servlet
-
doService
void doService(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse) throws javax.servlet.ServletException, java.io.IOExceptionUtility that delegates to the actual service method of the servlet wrapped with a contextual request (i.e. with correctly computed path info).We need to suppress deprecation coz we use HttpServletRequestWrapper, which implements deprecated API for backwards compatibility.
- Throws:
javax.servlet.ServletExceptionjava.io.IOException
-
doServiceImpl
private void doServiceImpl(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException- Throws:
javax.servlet.ServletExceptionjava.io.IOException
-
getKey
java.lang.String getKey()
-
-