# Printing Session Values for debugging

**URL:** <https://community.gatling.io/t/printing-session-values-for-debugging/6568>\
**Category:** Gatling (Open-Source)\
**Created:** [March 12, 2022, 3:08am UTC](https://community.gatling.io/t/printing-session-values-for-debugging/6568 "2022-03-12T03:08:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AshishChadda](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@AshishChadda](https://community.gatling.io/u/AshishChadda)\
**Post date:** [March 12, 2022, 3:08am UTC](https://community.gatling.io/t/printing-session-values-for-debugging/6568/1 "2022-03-12T03:08:33Z")

</div>

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

Reference: [Gatling - Debugging](https://gatling.io/docs/gatling/guides/debugging/)

```java
.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;
    })
);

```

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [March 12, 2022, 1:16pm UTC](https://community.gatling.io/t/printing-session-values-for-debugging/6568/2 "2022-03-12T13:16:29Z")

</div>

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:

```java
.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;
});

```

---

<div class="post-metadata">

**Author:** ![AshishChadda](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@AshishChadda](https://community.gatling.io/u/AshishChadda)\
**Post date:** [March 12, 2022, 2:51pm UTC](https://community.gatling.io/t/printing-session-values-for-debugging/6568/3 "2022-03-12T14:51:51Z")

</div>

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](https://gatling.io/docs/gatling/reference/current/core/session/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.

```auto
.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;
});

```

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [March 12, 2022, 10:52pm UTC](https://community.gatling.io/t/printing-session-values-for-debugging/6568/4 "2022-03-12T22:52:32Z")

</div>

I realize that I’ve forgotten to override Java Session’s toString, see [Core: Java Session misses toString override · Issue #4228 · gatling/gatling · GitHub](https://github.com/gatling/gatling/issues/4228)

As a workaround, you can do:

```java
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.

---

<div class="post-metadata">

**Author:** ![AshishChadda](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@AshishChadda](https://community.gatling.io/u/AshishChadda)\
**Post date:** [March 12, 2022, 11:37pm UTC](https://community.gatling.io/t/printing-session-values-for-debugging/6568/5 "2022-03-12T23:37:44Z")

</div>

> [@slandelle](#):
>
> `session.asScala()`

Thanks, I see session details printed now.

---

<div class="post-metadata">

**Author:** ![Disoriented](https://avatars.discourse-cdn.com/v4/letter/d/ecd19e/32.png) [@Disoriented](https://community.gatling.io/u/Disoriented)\
**Post date:** [March 16, 2022, 2:39am UTC](https://community.gatling.io/t/printing-session-values-for-debugging/6568/6 "2022-03-16T02:39:40Z")

</div>

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.
