I am using gatling with java and maven.
My goal is to login to an application (HTTP request which is working fine)
after logging in I need to take ApiToken from the response (which is working fine)
now I need to manipulate the token by concatinating it with “$” and then encode it to base64 format.
using this encoded token I want to establish a websocket connection and continue the load test.
Problem : I am unable to do the encoding operation. I tried creating a regular java function under the class which extends simulation, it gives me error. is there a better way to resolve this? Maybe a code snippet can help!
I’ve done it this way. Not sure why getBytes() is not working. Im working on java 22.
and imported below
import java.util.*;
import java.lang.String;
import java.lang.Object;
Thanks Samir! I understood slandelle.
the getByte() issue is fixed.
I cant access the app due to downtime now. But the next question is how do I access the encoded session token in the next exec block when I’m trying to establish the websocket connection?
I need to pass the encoded token grabbed earlier to the next exec block (starts line 49). so I am trying to pass it like #{token}. when I use session.getString(“token”), it cant find the session variable, so how do i pass the session to the next exec given I don’t have anything to return in this block.
Thanks Samir.
The token is printed correctly. The new error im seeing this premature closure of websocket.
it shows OK for open ws connection but not sure if it is actually opening the connection.
About the “Premature close” exception, it means that the connection socket between Gatling and your server was closed before reaching the end of the body.
This can come from multiples reason like:
An intermediate server (proxy) forcely close the connection at some time
Wrong value for Content-length header.
Server answers correctly with 200 and correct headers, but don’t let the connection ends to transmit the full body (or the body is corrupted)