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>
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
FieldsModifier and TypeFieldDescriptionprivate final AtomicReference
<javax.servlet.http.HttpServlet> private final UriPatternMatcher
private final javax.servlet.http.HttpServlet
private final Key
<? extends javax.servlet.http.HttpServlet> -
Constructor Summary
ConstructorsConstructorDescriptionServletDefinition
(Key<? extends javax.servlet.http.HttpServlet> servletKey, UriPatternMatcher patternMatcher, Map<String, String> initParams, javax.servlet.http.HttpServlet servletInstance) -
Method Summary
Modifier and TypeMethodDescription<B,
V> V acceptExtensionVisitor
(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.void
(package private) void
doService
(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 void
doServiceImpl
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) get()
Provides an instance ofT
.(package private) String
getKey()
void
init
(javax.servlet.ServletContext servletContext, Injector injector, Set<javax.servlet.http.HttpServlet> initializedSoFar) boolean
service
(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) boolean
shouldServe
(String uri)
-
Field Details
-
servletKey
-
patternMatcher
-
initParams
-
servletInstance
private final javax.servlet.http.HttpServlet servletInstance -
httpServlet
-
-
Constructor Details
-
ServletDefinition
public ServletDefinition(Key<? extends javax.servlet.http.HttpServlet> servletKey, UriPatternMatcher patternMatcher, Map<String, String> initParams, javax.servlet.http.HttpServlet servletInstance)
-
-
Method Details
-
get
Description copied from interface:Provider
Provides an instance ofT
.- Specified by:
get
in interfaceProvider<ServletDefinition>
- Specified by:
get
in interfacejavax.inject.Provider<ServletDefinition>
-
acceptExtensionVisitor
public <B,V> V acceptExtensionVisitor(BindingTargetVisitor<B, V> visitor, ProviderInstanceBinding<? extends B> binding) Description copied from interface:ProviderWithExtensionVisitor
Instructs 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:
acceptExtensionVisitor
in interfaceProviderWithExtensionVisitor<ServletDefinition>
-
shouldServe
-
init
public void init(javax.servlet.ServletContext servletContext, Injector injector, Set<javax.servlet.http.HttpServlet> initializedSoFar) throws javax.servlet.ServletException - Throws:
javax.servlet.ServletException
-
destroy
-
service
public boolean service(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse) throws IOException, javax.servlet.ServletException Wrapper 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:
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, IOException Utility 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.ServletException
IOException
-
doServiceImpl
private void doServiceImpl(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException - Throws:
javax.servlet.ServletException
IOException
-
getKey
String getKey()
-