Interface TrafficParrotServices


public interface TrafficParrotServices
What Traffic Parrot offers a custom extension beyond its own inputs: an HTTP response transformer, a Handlebars helper, or a JMS, IBM MQ or file message transformer.

To get it, give the extension a public constructor with one parameter, of type TrafficParrotServices; Traffic Parrot calls it instead of the no-argument constructor, so an extension without one is created as before, as is one whose constructor takes anything more. Keep it, or a service from it, in a field: it stays valid for the extension's lifetime, is safe to use from any thread, and each service reads its configuration on each use, so an edit takes effect without a restart. Ask a service for something, such as a DataSource, when the extension runs, not in its constructor: Traffic Parrot also creates extensions to list them in its web interface. In the extension's own unit tests, pass withDatabaseConnections(com.trafficparrot.sdk.database.DatabaseConnections) or any implementation that overrides the services the extension uses. Declare the SDK dependency with provided scope: a constructor taking a TrafficParrotServices from a relocated copy of the SDK bundled in the extension jar is refused.

An HTTP response transformer serving a scenario that has its own port gets that scenario's services. Every other extension gets the services of the scenario selected in Traffic Parrot.

Every service is a default method, and services added in later versions will be too, so an implementation written for a test keeps compiling. Inside Traffic Parrot no service method returns null.

  • Method Details

    • databaseConnections

      default DatabaseConnections databaseConnections()
      The database connections configured in database-connections.json.
      Throws:
      UnsupportedOperationException - if this implementation does not provide them, as a test's may not
    • withDatabaseConnections

      static TrafficParrotServices withDatabaseConnections(DatabaseConnections databaseConnections)
      Services with these database connections, for an extension's unit test: new MyExtension(TrafficParrotServices.withDatabaseConnections(connectionId -> inMemoryDataSource)).