Interface NodeCommandInterceptor

All Superinterfaces:
AutoCloseable, Closeable

public interface NodeCommandInterceptor extends Closeable
SPI for intercepting WebDriver commands executed through the Node. Implementations are discovered at runtime via ServiceLoader and may be provided at startup via --ext.

Interceptors are called in the order they are loaded. Each interceptor receives a next callable that, when invoked, advances to the next interceptor or executes the actual command.

The lifecycle of an enabled interceptor mirrors the LocalNode that hosts it: initialize(Config, EventBus) is called once at node startup and close() is called once when the node shuts down. Implementations that hold resources (thread pools, file handles, network connections) should release them in close().

Typical usage — subscribe to session-lifecycle events in initialize(Config, EventBus) (via the bus), then annotate or observe each command in intercept(SessionId, HttpRequest, Callable):

public void initialize(Config config, EventBus bus) {
  bus.addListener(SessionCreatedEvent.listener(data -> onSessionStarted(data)));
  bus.addListener(SessionClosedEvent.listener(data -> onSessionStopped(data)));
}

public HttpResponse intercept(SessionId id, HttpRequest req, Callable<HttpResponse> next)
    throws Exception {
  before(id, req);
  HttpResponse response = next.call();
  after(id, req, response);
  return response;
}
  • Method Details

    • isEnabled

      boolean isEnabled(Config config)
      Returns true when this interceptor should be activated for the given config.
    • initialize

      void initialize(Config config, EventBus bus)
      Called once during node startup after isEnabled(Config) returns true. Implementations should subscribe to session-lifecycle events on the bus here.
    • close

      default void close() throws IOException
      Called once when the LocalNode shuts down. Implementations should release any resources acquired in initialize(Config, EventBus) (thread pools, open files, network connections).

      The default implementation is a no-op; override only when cleanup is needed.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • intercept

      HttpResponse intercept(SessionId id, HttpRequest req, Callable<HttpResponse> next) throws Exception
      Wraps execution of a single WebDriver HTTP command. Implementations MUST call next.call() exactly once and return its result (possibly augmented).
      Parameters:
      id - the session ID extracted from the request URI
      req - the incoming HTTP request
      next - callable that advances to the next interceptor or executes the command
      Returns:
      the HTTP response to return to the caller
      Throws:
      Exception