Record Class HttpRunEvent

java.lang.Object
java.lang.Record
io.karatelabs.core.HttpRunEvent
All Implemented Interfaces:
RunEvent

public record HttpRunEvent(RunEventType type, HttpRequest request, HttpResponse response, ScenarioRuntime scenarioRuntime, long timeStamp) extends Record implements RunEvent
HTTP-level events (HTTP_ENTER, HTTP_EXIT).

Enables commercial extensions to capture HTTP request/response data for reports like OpenAPI coverage, request logging, or mock injection.

Usage with pattern matching:

 listener = event -> switch (event) {
     case HttpRunEvent e when e.type() == HTTP_EXIT -> {
         Step step = e.getCurrentStep();
         HttpRequest req = e.request();
         HttpResponse res = e.response();
         // Process HTTP data
         yield true;
     }
     default -> true;
 };
 

Returning false from HTTP_ENTER listener skips the actual HTTP request. This enables commercial mocking/stubbing tools to intercept requests.

  • Constructor Details

    • HttpRunEvent

      public HttpRunEvent(RunEventType type, HttpRequest request, HttpResponse response, ScenarioRuntime scenarioRuntime, long timeStamp)
      Creates an instance of a HttpRunEvent record class.
      Parameters:
      type - the value for the type record component
      request - the value for the request record component
      response - the value for the response record component
      scenarioRuntime - the value for the scenarioRuntime record component
      timeStamp - the value for the timeStamp record component
  • Method Details

    • enter

      public static HttpRunEvent enter(HttpRequest request, ScenarioRuntime sr)
      Creates an HTTP_ENTER event fired before the HTTP request is made. Return false from listener to skip the request.
    • exit

      public static HttpRunEvent exit(HttpRequest request, HttpResponse response, ScenarioRuntime sr)
      Creates an HTTP_EXIT event fired after the HTTP response is received. Always fires, even for skipped requests (response.isSkipped() == true).
    • getType

      public RunEventType getType()
      Description copied from interface: RunEvent
      Returns the event type.
      Specified by:
      getType in interface RunEvent
    • getTimeStamp

      public long getTimeStamp()
      Description copied from interface: RunEvent
      Returns the timestamp when this event occurred (epoch milliseconds).
      Specified by:
      getTimeStamp in interface RunEvent
    • toJson

      public Map<String,Object> toJson()
      Description copied from interface: RunEvent
      Serializes this event to a map for JSONL output.
      Specified by:
      toJson in interface RunEvent
    • getCurrentStep

      public Step getCurrentStep()
      Convenience method to get the currently executing step. Use this to correlate HTTP requests to the step that triggered them.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • type

      public RunEventType type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • request

      public HttpRequest request()
      Returns the value of the request record component.
      Returns:
      the value of the request record component
    • response

      public HttpResponse response()
      Returns the value of the response record component.
      Returns:
      the value of the response record component
    • scenarioRuntime

      public ScenarioRuntime scenarioRuntime()
      Returns the value of the scenarioRuntime record component.
      Returns:
      the value of the scenarioRuntime record component
    • timeStamp

      public long timeStamp()
      Returns the value of the timeStamp record component.
      Returns:
      the value of the timeStamp record component