Class CDORestJettyServer

java.lang.Object
org.eclipse.net4j.util.event.Notifier
org.eclipse.net4j.util.lifecycle.Lifecycle
org.eclipse.emf.cdo.server.rest.jetty.CDORestJettyServer
All Implemented Interfaces:
AutoCloseable, CDORestTransport, org.eclipse.net4j.util.event.INotifier, org.eclipse.net4j.util.event.INotifier.INotifier2, org.eclipse.net4j.util.lifecycle.IDeactivateable, org.eclipse.net4j.util.lifecycle.ILifecycle, org.eclipse.net4j.util.lifecycle.ILifecycle.DeferrableActivation

public final class CDORestJettyServer extends org.eclipse.net4j.util.lifecycle.Lifecycle implements CDORestTransport, AutoCloseable
Owns an optional standalone Jetty 12 listener for a CDO REST service. It creates a native Jetty Core handler tree and never depends on a Servlet or Jetty EE implementation. Embedders that already own a Jetty server can instead mount CDORestJettyHandler directly and retain ownership of their server lifecycle.

The listener binds to loopback by default. Operators choose the bind address and whether to enable TLS. TLS does not provide CDO authentication or repository authorization. TLS uses the standard JSSE system properties javax.net.ssl.keyStore, javax.net.ssl.keyStorePassword, and javax.net.ssl.keyStoreType.

Author:
Eike Stepper
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.eclipse.net4j.util.event.Notifier

    org.eclipse.net4j.util.event.Notifier.Cancelation

    Nested classes/interfaces inherited from interface org.eclipse.net4j.util.lifecycle.ILifecycle

    org.eclipse.net4j.util.lifecycle.ILifecycle.DeferrableActivation

    Nested classes/interfaces inherited from interface org.eclipse.net4j.util.event.INotifier

    org.eclipse.net4j.util.event.INotifier.INotifier2
  • Field Summary

    Fields inherited from class org.eclipse.net4j.util.lifecycle.Lifecycle

    USE_LABEL

    Fields inherited from interface CDORestTransport

    PRODUCT_GROUP
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a server with the default loopback address, port, and mount path.
    CDORestJettyServer(CDORestService service, String host, int port, String contextPath, boolean tlsEnabled)
    Creates a configured Jetty listener.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a public static resource context before the listener is activated.
    void
    Stops and destroys the owned listener.
    protected void
     
    protected void
     
    int
    Returns the port assigned by the operating system after startup.
    boolean
    Indicates whether the owned Jetty listener is currently running.
    void
    setContextPath(String contextPath)
    Sets the path handled by the owned Jetty context.
    void
    Sets the network interface address before the listener is activated.
    void
    setPort(int port)
    Sets the TCP port before the listener is activated.
    void
    Supplies the service that receives requests from this transport.
    void
    setTLSEnabled(boolean tlsEnabled)
    Enables TLS for the owned listener using the configured JSSE key store.
    void
    Starts the listener.

    Methods inherited from class org.eclipse.net4j.util.lifecycle.Lifecycle

    activate, checkActive, checkArg, checkArg, checkInactive, checkNull, checkState, checkState, deactivate, deferredActivate, doAfterActivate, doBeforeActivate, doBeforeDeactivate, doCancelActivation, dump, getLifecycleState, isActive, isDeferredActivation, toString

    Methods inherited from class org.eclipse.net4j.util.event.Notifier

    addListener, addUniqueListener, fireEvent, fireEvent, fireEvent, fireThrowable, firstListenerAdded, getListeners, getNotificationService, hasListener, hasListeners, lastListenerRemoved, listenerAdded, listenerRemoved, removeListener

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.eclipse.net4j.util.lifecycle.ILifecycle

    activate, deactivate, getLifecycleState, isActive

    Methods inherited from interface org.eclipse.net4j.util.event.INotifier

    addListener, getListeners, hasListeners, removeListener
  • Constructor Details

    • CDORestJettyServer

      public CDORestJettyServer()
      Creates a server with the default loopback address, port, and mount path. Factory attributes or setter calls can further configure the server before activation.
    • CDORestJettyServer

      public CDORestJettyServer(CDORestService service, String host, int port, String contextPath, boolean tlsEnabled)
      Creates a configured Jetty listener. The server does not start until start() is called.
      Parameters:
      service - the shared REST service
      host - the interface address to bind, preferably 127.0.0.1
      port - the TCP port to bind, or zero to request an available port
      contextPath - the customer-visible mount path, such as /cdo
      tlsEnabled - whether the connector uses the configured JSSE key store
      Throws:
      IllegalArgumentException - if the port or mount path is invalid
      NullPointerException - if a required argument is null
  • Method Details

    • setRestService

      public void setRestService(CDORestService service)
      Description copied from interface: CDORestTransport
      Supplies the service that receives requests from this transport. The service calls this method before activation.
      Specified by:
      setRestService in interface CDORestTransport
      Parameters:
      service - the transport-neutral service to delegate requests to
    • setHost

      public void setHost(String host)
      Sets the network interface address before the listener is activated.
      Parameters:
      host - the non-blank address to bind
      Throws:
      IllegalArgumentException - if the host is blank
    • setPort

      public void setPort(int port)
      Sets the TCP port before the listener is activated. Zero requests an operating-system-assigned port.
      Parameters:
      port - the port to bind, between zero and 65535
      Throws:
      IllegalArgumentException - if the port is outside the supported range
    • setContextPath

      public void setContextPath(String contextPath)
      Sets the path handled by the owned Jetty context.
      Parameters:
      contextPath - an absolute path such as /cdo
      Throws:
      IllegalArgumentException - if the path is invalid
    • setTLSEnabled

      public void setTLSEnabled(boolean tlsEnabled)
      Enables TLS for the owned listener using the configured JSSE key store.
      Parameters:
      tlsEnabled - whether TLS is enabled
    • addStaticResource

      public void addStaticResource(StaticResourceMapping mapping)
      Adds a public static resource context before the listener is activated.
      Parameters:
      mapping - the context path and resource directory to expose
    • start

      public void start() throws Exception
      Starts the listener. This convenience method delegates to the component lifecycle.
      Throws:
      Exception - if Jetty cannot bind, initialize, or start
      IllegalStateException - if the server has already been started
    • isStarted

      public boolean isStarted()
      Indicates whether the owned Jetty listener is currently running.
      Returns:
      true if Jetty has started and remains running
    • getLocalPort

      public int getLocalPort()
      Returns the port assigned by the operating system after startup.
      Returns:
      the bound TCP port
      Throws:
      IllegalStateException - if the server has not started
    • close

      public void close() throws Exception
      Stops and destroys the owned listener. The shared REST service remains available to other transports.
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception - if Jetty reports a shutdown failure
    • doActivate

      protected void doActivate() throws Exception
      Overrides:
      doActivate in class org.eclipse.net4j.util.lifecycle.Lifecycle
      Throws:
      Exception
    • doDeactivate

      protected void doDeactivate() throws Exception
      Overrides:
      doDeactivate in class org.eclipse.net4j.util.lifecycle.Lifecycle
      Throws:
      Exception