Class ServletDefinition

java.lang.Object
com.google.inject.servlet.ServletDefinition
All Implemented Interfaces:
Provider<ServletDefinition>, ProviderWithExtensionVisitor<ServletDefinition>, javax.inject.Provider<ServletDefinition>

class ServletDefinition extends 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 final AtomicReference<javax.servlet.http.HttpServlet>
     
    private final Map<String,String>
     
    private final UriPatternMatcher
     
    private final javax.servlet.http.HttpServlet
     
    private final Key<? extends javax.servlet.http.HttpServlet>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    ServletDefinition(Key<? extends javax.servlet.http.HttpServlet> servletKey, UriPatternMatcher patternMatcher, Map<String,String> initParams, javax.servlet.http.HttpServlet servletInstance)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <B, V> V
    Instructs the extension determine if the visitor is an instance of a custom extension visitor, and if so, visit it using that method.
    void
    destroy(Set<javax.servlet.http.HttpServlet> destroyedSoFar)
     
    (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 of T.
    (package private) String
     
    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
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • servletKey

      private final Key<? extends javax.servlet.http.HttpServlet> servletKey
    • patternMatcher

      private final UriPatternMatcher patternMatcher
    • initParams

      private final Map<String,String> initParams
    • servletInstance

      private final javax.servlet.http.HttpServlet servletInstance
    • httpServlet

      private final AtomicReference<javax.servlet.http.HttpServlet> 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

      public ServletDefinition get()
      Description copied from interface: Provider
      Provides an instance of T.
      Specified by:
      get in interface Provider<ServletDefinition>
      Specified by:
      get in interface javax.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 interface ProviderWithExtensionVisitor<ServletDefinition>
    • shouldServe

      boolean shouldServe(String uri)
    • 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

      public void destroy(Set<javax.servlet.http.HttpServlet> destroyedSoFar)
    • 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 servlet
      javax.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()