Class GuiceServlet

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
com.peterphi.std.guice.web.servlet.GuiceServlet
All Implemented Interfaces:
GuiceApplication, Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public abstract class GuiceServlet extends javax.servlet.http.HttpServlet implements GuiceApplication
Basic Guice-aware servlet that is configured at invocation time and restarted using GuiceRegistry
Feeds Servlet lifecycle events back to GuiceRegistry to perform orderly shutdown of services
Overrides HttpServlet.service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) to perform lazy configuration. See the doService method if you need to override service
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final void
    Called when a new Injector has been created, after Guice injection has been applied to this instance.
    final void
     
    protected void
    doService(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
    Calls HttpServlet.service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) should a subclass need to implement that method
    protected final void
    service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
     
    abstract void
    Called when an Injector is stopping and before the ShutdownManager for the GuiceRegistry is signalled
    The GuiceRegistry will wait for this method to return before proceeding.

    Methods inherited from class javax.servlet.http.HttpServlet

    doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service

    Methods inherited from class javax.servlet.GenericServlet

    getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log

    Methods inherited from class java.lang.Object

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

    • GuiceServlet

      public GuiceServlet()
  • Method Details

    • service

      protected final void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
      Overrides:
      service in class javax.servlet.http.HttpServlet
      Throws:
      javax.servlet.ServletException
      IOException
    • doService

      protected void doService(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws javax.servlet.ServletException, IOException
      Calls HttpServlet.service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) should a subclass need to implement that method
      Parameters:
      req -
      resp -
      Throws:
      javax.servlet.ServletException
      IOException
    • configured

      public final void configured()
      Description copied from interface: GuiceApplication
      Called when a new Injector has been created, after Guice injection has been applied to this instance.

      No guarantees are made about the order in which GuiceApplication instances will be called

      Specified by:
      configured in interface GuiceApplication
    • destroy

      public final void destroy()
      Specified by:
      destroy in interface javax.servlet.Servlet
      Overrides:
      destroy in class javax.servlet.GenericServlet
    • stopping

      public abstract void stopping()
      Description copied from interface: GuiceApplication
      Called when an Injector is stopping and before the ShutdownManager for the GuiceRegistry is signalled
      The GuiceRegistry will wait for this method to return before proceeding. No guarantees are made about the order in which GuiceApplication instances will be called
      Specified by:
      stopping in interface GuiceApplication