Class JerseyServer

java.lang.Object
io.bdeploy.jersey.JerseyServer
All Implemented Interfaces:
RegistrationTarget, AutoCloseable

public class JerseyServer extends Object implements AutoCloseable, RegistrationTarget
Encapsulates required functionality from the Grizzly HttpServer with the Jersey handlers.

Use register(Object) to register additional resource, filters and providers before starting the server.

  • Field Details

  • Constructor Details

    • JerseyServer

      public JerseyServer(int port, KeyStore store, char[] passphrase)
      Parameters:
      port - the port to listen on
      store - the keystore carrying the private certificate/key material for SSL.
      passphrase - the passphrase for the keystore.
  • Method Details

    • getKeyStore

      public KeyStore getKeyStore()
      Specified by:
      getKeyStore in interface RegistrationTarget
      Returns:
      the KeyStore which can be used to perform token validation.
    • afterStartup

      public CompletableFuture<RegistrationTarget> afterStartup()
      Specified by:
      afterStartup in interface RegistrationTarget
      Returns:
      a CompletableFuture which is completed after the server has completed startup.
    • getRemoteActivityReporter

      public ActivityReporter getRemoteActivityReporter()
      Returns:
      an ActivityReporter which can broadcast to remote.
    • setAuditor

      public void setAuditor(Auditor auditor)
      Sets the auditor that will be used by the server to log requests. The auditor will be closed when the server is terminated.
      Parameters:
      auditor - auditor to log requests
    • setUserValidator

      public void setUserValidator(JerseyAuthenticationProvider.UserValidator validator)
      Parameters:
      validator - a validator which can verify a user exists and is allowed to proceed.
    • registerResource

      public void registerResource(AutoCloseable closeable)
      Description copied from interface: RegistrationTarget
      Registers a resource that will be closed when the server is stopped.
      Specified by:
      registerResource in interface RegistrationTarget
      Parameters:
      closeable - resource to close
    • register

      public void register(Object provider)
      Registers a class or an instance to be used in this server.
      Specified by:
      register in interface RegistrationTarget
      Parameters:
      provider - a Class or Object instance to register. Also supports registration of custom Binder instances which allow custom dependency injection in services.
    • addHandler

      public void addHandler(org.glassfish.grizzly.http.server.HttpHandler handler, org.glassfish.grizzly.http.server.HttpHandlerRegistration registration)
      Specified by:
      addHandler in interface RegistrationTarget
      Parameters:
      handler - register an additional handler at the given location. pass HttpHandlerRegistration.ROOT to register at the root of the server (e.g. the root web resources).
    • removeHandler

      public void removeHandler(org.glassfish.grizzly.http.server.HttpHandler handler)
      Specified by:
      removeHandler in interface RegistrationTarget
      Parameters:
      handler - a previously registered handler.
    • registerWebsocketApplication

      public void registerWebsocketApplication(String urlMapping, org.glassfish.grizzly.websockets.WebSocketApplication wsa)
      Description copied from interface: RegistrationTarget
      Registers a WebSocket application.

      Note: All WebSocketApplications are registered in the '/ws' context path.

      Specified by:
      registerWebsocketApplication in interface RegistrationTarget
      Parameters:
      urlMapping - the path where to host the application. May contain wildcards.
      wsa - the WebSocketApplication
    • updateLogging

      public static void updateLogging()
    • start

      public void start()
      Start the server as configured.
    • registerDefaultResources

      public void registerDefaultResources(org.glassfish.jersey.server.ResourceConfig config)
      Parameters:
      config - a ResourceConfig to enrich with all the default resources and features used by the BDeploy JAX-RS infrastructure. Allows to create additional JAX-RS applications which use the same setup as BDeploy itself. This is useful e.g. for plugins which should use the same filters/features as BDeploy.
    • isRunning

      public boolean isRunning()
      Returns:
      whether the server is running.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • join

      public boolean join()