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.CancelationNested classes/interfaces inherited from interface org.eclipse.net4j.util.lifecycle.ILifecycle
org.eclipse.net4j.util.lifecycle.ILifecycle.DeferrableActivationNested 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_LABELFields inherited from interface CDORestTransport
PRODUCT_GROUP -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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 TypeMethodDescriptionvoidaddStaticResource(StaticResourceMapping mapping) Adds a public static resource context before the listener is activated.voidclose()Stops and destroys the owned listener.protected voidprotected voidintReturns the port assigned by the operating system after startup.booleanIndicates whether the owned Jetty listener is currently running.voidsetContextPath(String contextPath) Sets the path handled by the owned Jetty context.voidSets the network interface address before the listener is activated.voidsetPort(int port) Sets the TCP port before the listener is activated.voidsetRestService(CDORestService service) Supplies the service that receives requests from this transport.voidsetTLSEnabled(boolean tlsEnabled) Enables TLS for the owned listener using the configured JSSE key store.voidstart()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, toStringMethods inherited from class org.eclipse.net4j.util.event.Notifier
addListener, addUniqueListener, fireEvent, fireEvent, fireEvent, fireThrowable, firstListenerAdded, getListeners, getNotificationService, hasListener, hasListeners, lastListenerRemoved, listenerAdded, listenerRemoved, removeListenerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.net4j.util.lifecycle.ILifecycle
activate, deactivate, getLifecycleState, isActiveMethods 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 untilstart()is called.- Parameters:
service- the shared REST servicehost- the interface address to bind, preferably127.0.0.1port- the TCP port to bind, or zero to request an available portcontextPath- the customer-visible mount path, such as/cdotlsEnabled- whether the connector uses the configured JSSE key store- Throws:
IllegalArgumentException- if the port or mount path is invalidNullPointerException- if a required argument isnull
-
-
Method Details
-
setRestService
Description copied from interface:CDORestTransportSupplies the service that receives requests from this transport. The service calls this method before activation.- Specified by:
setRestServicein interfaceCDORestTransport- Parameters:
service- the transport-neutral service to delegate requests to
-
setHost
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
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
Adds a public static resource context before the listener is activated.- Parameters:
mapping- the context path and resource directory to expose
-
start
Starts the listener. This convenience method delegates to the component lifecycle.- Throws:
Exception- if Jetty cannot bind, initialize, or startIllegalStateException- if the server has already been started
-
isStarted
public boolean isStarted()Indicates whether the owned Jetty listener is currently running.- Returns:
trueif 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
Stops and destroys the owned listener. The shared REST service remains available to other transports.- Specified by:
closein interfaceAutoCloseable- Throws:
Exception- if Jetty reports a shutdown failure
-
doActivate
-
doDeactivate
-