Skip to content

Stub Configuration, Interceptors

Tamás Kőhegyi edited this page Aug 31, 2022 · 8 revisions

What are the interceptors?

Interceptors are classes those intercept either requests or responses (or both) and do whatever they would like to do with the intercepted messages. See how to use such interceptor classes in the stub configuration file below.


Object: interceptors This object is optional in the stub configuration. If exists, only a single object is acceptable. Under this object the used interceptors have to be defined.

{
  "wilmaStubConfiguration": {
    ...,
    "interceptors": [
      { ... }
    ]
    ...
  }
}

Object: interceptor

An interceptor object holds the definition of a custom interceptor with its own parameters. An interceptor class must implement com.epam.wilma.domain.stubconfig.interceptor.RequestInterceptor interface or com.epam.wilma.domain.stubconfig.interceptor.ResponseInterceptor interface or both. If the given class implements both interfaces then both the request and the response will be available for the interceptor class.

{
    "name": ...,
    "class": ...,
    "parameters": [ ... ]
}

Where

  • name - is the name of the interceptor, mandatory field
  • class - is the name of the interceptor class, will be used to load the class itself, mandatory field
  • parameters - is an optional array that may hold name/value pairs as parameters for the specific interceptor

Examples

You may find some example interceptor classes and configuration files here as part of the Wilma functional tests.


Built-in Interceptors

HeaderUpdateInterceptor an interceptor for both Requests and Responses, to remove and add headers listed in parameters.

If a parameter name is "REMOVE" then the header specified in value parameter will be removed. In any other case a new header will be added with name and value. Beware that the response header modification works only if Response Message Volatility is enabled.

Example usage:

{
  "wilmaStubConfiguration": {
    "interceptors": [
      {
        "name": "STS-Header-Remover-Interceptor",
        "class": "HeaderUpdateInterceptor",
        "parameters" : [
          { "name": "REMOVE", "value": "X-XSS-Protection" },
          { "name": "REMOVE", "value": "upgrade-insecure-requests" },
          { "name": "REMOVE", "value": "Strict-Transport-Security" },
          { "name": "HeaderUpdateInterceptor", "value": "on" }
        ]
      }
    ]
  }
}
Clone this wiki locally