Printing Session Values for debugging

Hi, I am trying to capture the session details in JAVA using the below code but unfortunately, it is not working.

Reference: Gatling - Debugging

.exec(
  http("request_5")
    .post("/services/login/json")
    .formParam("userName", "xyz")
    .formParam("password", "***")
    .formParam("saveUserName", "false")
    .formParam("isSubmitting", "true")
    .exec(session -> {
      System.out.println(session.getString("session"));
      return session;
    })
);

By “it’s not working”, you mean “it doesn’t compile”.

When things don’t compile, it means you have a syntax error.

Indeed, your second exec block is not at the right place:

.exec(
  http("request_5")
    .post("/services/login/json")
    .formParam("userName", "xyz")
    .formParam("password", "***")
    .formParam("saveUserName", "false")
    .formParam("isSubmitting", "true")
)
.exec(session -> {
  System.out.println(session.getString("session"));
  return session;
});

Thanks Stéphane, your are right. Actually, we are doing POC to migrate from Jmeter to Gatling. Understand there’s a steep learning curve to achieve this.

BTW, I did try the above code but it is not printing session details. I have gone through the Session API tutorial - Gatling - Session API but not sure how to retrieve the content and what all attributes a session holds. I think there’s an issue with my println statement:
System.out.println(session.getString(“session”));
Here .getString(“What should I write here to retrieve all the session details”)

My main goal is to capture responses for the failed transactions/requests. Many Thanks in advance, I will work with Arnaud from gatling to get more details.

.exec(
  http("request_5")
    .post("/services/login/json")
    .formParam("userName", "xyz")
    .formParam("password", "***")
    .formParam("saveUserName", "false")
    .formParam("isSubmitting", "true")
)
.exec(session -> {
  System.out.println(session.getString("session"));
  return session;
});

I realize that I’ve forgotten to override Java Session’s toString, see Core: Java Session misses toString override · Issue #4228 · gatling/gatling · GitHub

As a workaround, you can do:

System.out.println(session.asScala());

My main goal is to capture responses for the failed transactions/requests.

That’s not the kind of things you’ll find in the Session. The Session is only the memory space for each virtual user where you can store and fetch back some data.

Thanks, I see session details printed now.

Oh, wow. I’ve been so busy with my head down writing tests, I didn’t think long enough to report a bug. Been working with Java DSL (thank you, by the way) and just relied on independently logging my vars but I enabled trace most of the time and looked at the session vars there.