Class EventSourceServlet

java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
org.eclipse.jetty.ee10.servlets.EventSourceServlet
All Implemented Interfaces:
jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable

public abstract class EventSourceServlet extends jakarta.servlet.http.HttpServlet

A servlet that implements the event source protocol, also known as "server sent events".

This servlet must be subclassed to implement abstract method newEventSource(HttpServletRequest) to return an instance of EventSource that allows application to listen for event source events and to emit event source events.

This servlet supports the following configuration parameters:

  • heartBeatPeriod, that specifies the heartbeat period, in seconds, used to check whether the connection has been closed by the client; defaults to 10 seconds.

NOTE: there is currently no support for last-event-id.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected class 
     
  • Field Summary

    Fields inherited from class jakarta.servlet.http.HttpServlet

    LEGACY_DO_HEAD
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    protected void
    doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
     
    void
     
    protected abstract EventSource
    newEventSource(jakarta.servlet.http.HttpServletRequest request)
     
    protected void
    open(EventSource eventSource, EventSource.Emitter emitter)
     
    protected void
    respond(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
     

    Methods inherited from class jakarta.servlet.http.HttpServlet

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

    Methods inherited from class jakarta.servlet.GenericServlet

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

    Methods inherited from class java.lang.Object

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

    • EventSourceServlet

      public EventSourceServlet()
  • Method Details

    • init

      public void init() throws jakarta.servlet.ServletException
      Overrides:
      init in class jakarta.servlet.GenericServlet
      Throws:
      jakarta.servlet.ServletException
    • destroy

      public void destroy()
      Specified by:
      destroy in interface jakarta.servlet.Servlet
      Overrides:
      destroy in class jakarta.servlet.GenericServlet
    • doGet

      protected void doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException
      Overrides:
      doGet in class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
      IOException
    • newEventSource

      protected abstract EventSource newEventSource(jakarta.servlet.http.HttpServletRequest request)
    • respond

      protected void respond(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws IOException
      Throws:
      IOException
    • open

      protected void open(EventSource eventSource, EventSource.Emitter emitter) throws IOException
      Throws:
      IOException