Class CDORestService

java.lang.Object
org.eclipse.net4j.util.event.Notifier
org.eclipse.net4j.util.lifecycle.Lifecycle
org.eclipse.emf.cdo.server.rest.CDORestService
All Implemented Interfaces:
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 CDORestService extends org.eclipse.net4j.util.lifecycle.Lifecycle
The embeddable entry point for the versioned CDO graph REST API. It dispatches transport-neutral requests through an IRepositoryProvider, which explicitly controls the repository names and aliases exposed to REST callers. The service does not authenticate HTTP callers or enforce CDO authorization; operators are responsible for suitable network and HTTP access protection.

Activation makes REST requests available, starts transports added with addTransport(CDORestTransport), and creates long-lived internal repository contexts as repositories are first requested. Requests through a customer-owned transport require an activated service; activate the service without adding an owned transport, then call service(CDORestRequest, CDORestResponse) for each request.

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
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a REST service for an explicit alias-to-repository mapping.
    CDORestService(Map<String, IRepository> repositories, CDORestConfiguration configuration)
    Creates a REST service for an explicit alias-to-repository mapping with the supplied configuration.
    CDORestService(IRepositoryProvider repositoryProvider)
    Creates a REST service that resolves repository routes through the supplied provider.
    CDORestService(IRepositoryProvider repositoryProvider, CDORestConfiguration configuration)
    Creates a REST service with an explicit configuration.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a transport that follows this service's lifecycle.
    protected void
     
    protected void
     
    Returns the repository provider used for REST lookup and optional name enumeration.
    void
    Handles one request synchronously.

    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.event.INotifier

    addListener, getListeners, hasListeners, removeListener
  • Constructor Details

    • CDORestService

      public CDORestService(Map<String, IRepository> repositories)
      Creates a REST service for an explicit alias-to-repository mapping. The mapping is copied at construction time, and subsequent changes to the caller's map cannot alter repository exposure. The service uses the effective defaults from a new CDORestConfiguration.
      Parameters:
      repositories - REST-visible names mapped to active CDO repositories; names must contain only letters, digits, dots, underscores, and hyphens
      Throws:
      IllegalArgumentException - if a repository name is not a valid route segment
      NullPointerException - if the map, a name, or a repository is null
    • CDORestService

      public CDORestService(IRepositoryProvider repositoryProvider)
      Creates a REST service that resolves repository routes through the supplied provider. An enumerable provider may expose one or more aliases through the repository listing endpoint. A provider that does not implement name enumeration can still resolve direct repository routes, but the listing endpoint reports that enumeration is unsupported. Dynamic providers are consulted for each request and must make their lookup operations safe for concurrent calls. The service uses the effective defaults from a new CDORestConfiguration.
      Parameters:
      repositoryProvider - the provider used for direct repository lookup and optional name enumeration
      Throws:
      IllegalArgumentException - if an initially enumerated name is not a valid REST route segment
      NullPointerException - if the provider is null
    • CDORestService

      public CDORestService(IRepositoryProvider repositoryProvider, CDORestConfiguration configuration)
      Creates a REST service with an explicit configuration. The service copies it during construction, so later changes to the supplied instance do not affect the service.
      Parameters:
      repositoryProvider - the provider used for direct repository lookup and optional name enumeration
      configuration - the configuration to copy for this service
      Throws:
      IllegalArgumentException - if an initially enumerated name is not a valid REST route segment
      NullPointerException - if the provider or configuration is null
    • CDORestService

      public CDORestService(Map<String, IRepository> repositories, CDORestConfiguration configuration)
      Creates a REST service for an explicit alias-to-repository mapping with the supplied configuration. The mapping is copied at construction time, and later changes to the caller's map cannot alter repository exposure.
      Parameters:
      repositories - REST-visible names mapped to CDO repositories
      configuration - the configuration to copy for this service
      Throws:
      IllegalArgumentException - if a repository name is not a valid route segment
      NullPointerException - if the map, configuration, a name, or a repository is null
  • Method Details

    • getRepositoryProvider

      public IRepositoryProvider getRepositoryProvider()
      Returns the repository provider used for REST lookup and optional name enumeration.
      Returns:
      the configured repository provider
    • addTransport

      public void addTransport(CDORestTransport transport)
      Adds a transport that follows this service's lifecycle. Configure it before activating the service; the service starts and stops every added transport.
      Parameters:
      transport - the transport to start and stop with this service
      Throws:
      IllegalStateException - if this service has already been activated
      NullPointerException - if the transport is null
    • service

      public void service(CDORestRequest request, CDORestResponse response) throws IOException
      Handles one request synchronously. JSON responses are streamed to the supplied output stream. If the transport has already committed a response when serialization fails, the exception is propagated and no second document is appended. The request and response streams remain owned by the surrounding HTTP adapter.
      Parameters:
      request - the normalized request relative to the configured mount point
      response - the transport response adapter
      Throws:
      IOException - if request parsing or response streaming fails
    • 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