Package io.karatelabs.core
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 Summary
ConstructorsConstructorDescriptionHttpRunEvent(RunEventType type, HttpRequest request, HttpResponse response, ScenarioRuntime scenarioRuntime, long timeStamp) Creates an instance of aHttpRunEventrecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpRunEvententer(HttpRequest request, ScenarioRuntime sr) Creates an HTTP_ENTER event fired before the HTTP request is made.final booleanIndicates whether some other object is "equal to" this one.static HttpRunEventexit(HttpRequest request, HttpResponse response, ScenarioRuntime sr) Creates an HTTP_EXIT event fired after the HTTP response is received.Convenience method to get the currently executing step.longReturns the timestamp when this event occurred (epoch milliseconds).getType()Returns the event type.final inthashCode()Returns a hash code value for this object.request()Returns the value of therequestrecord component.response()Returns the value of theresponserecord component.Returns the value of thescenarioRuntimerecord component.longReturns the value of thetimeStamprecord component.toJson()Serializes this event to a map for JSONL output.final StringtoString()Returns a string representation of this record class.type()Returns the value of thetyperecord component.
-
Constructor Details
-
HttpRunEvent
public HttpRunEvent(RunEventType type, HttpRequest request, HttpResponse response, ScenarioRuntime scenarioRuntime, long timeStamp) Creates an instance of aHttpRunEventrecord class.- Parameters:
type- the value for thetyperecord componentrequest- the value for therequestrecord componentresponse- the value for theresponserecord componentscenarioRuntime- the value for thescenarioRuntimerecord componenttimeStamp- the value for thetimeStamprecord component
-
-
Method Details
-
enter
Creates an HTTP_ENTER event fired before the HTTP request is made. Return false from listener to skip the request. -
exit
Creates an HTTP_EXIT event fired after the HTTP response is received. Always fires, even for skipped requests (response.isSkipped() == true). -
getType
Description copied from interface:RunEventReturns the event type. -
getTimeStamp
public long getTimeStamp()Description copied from interface:RunEventReturns the timestamp when this event occurred (epoch milliseconds).- Specified by:
getTimeStampin interfaceRunEvent
-
toJson
Description copied from interface:RunEventSerializes this event to a map for JSONL output. -
getCurrentStep
Convenience method to get the currently executing step. Use this to correlate HTTP requests to the step that triggered them. -
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. -
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. -
equals
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 withObjects::equals(Object,Object); primitive components are compared with '=='. -
type
Returns the value of thetyperecord component.- Returns:
- the value of the
typerecord component
-
request
Returns the value of therequestrecord component.- Returns:
- the value of the
requestrecord component
-
response
Returns the value of theresponserecord component.- Returns:
- the value of the
responserecord component
-
scenarioRuntime
Returns the value of thescenarioRuntimerecord component.- Returns:
- the value of the
scenarioRuntimerecord component
-
timeStamp
public long timeStamp()Returns the value of thetimeStamprecord component.- Returns:
- the value of the
timeStamprecord component
-