Class ServletDefinition

    • 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>
      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 destroy​(java.util.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)  
      ServletDefinition get()
      Provides an instance of T.
      (package private) java.lang.String getKey()  
      void init​(javax.servlet.ServletContext servletContext, Injector injector, java.util.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​(java.lang.String uri)  
      • Methods inherited from class java.lang.Object

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

      • servletKey

        private final Key<? extends javax.servlet.http.HttpServlet> servletKey
      • 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

      • 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​(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.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:
        java.io.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,
                       java.io.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
        java.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.ServletException
        java.io.IOException
      • getKey

        java.lang.String getKey()