Problem capturing response body and printing a session value from the ".resources" block in Java

Gatling version: 3.11.5 (must be up to date)
Gatling flavor: [X ] java kotlin scala javascript typescript
Gatling build tool: maven gradle sbt bundle npm

I read the guidelines and how to ask a question topics.

Hello,
I have an .exec in a scenarioBuilder and the exec has ".resources() with many http requests.
I am trying to capture a value from the response from ONE of the http requests in the “.resources(” block. Example of the resources block is below. All I have seen on the internet suggest a certain way to saveAs and then print but Intellij is telling me the syntax is incorrect when it comes to the exec with session lambda expression:

        http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/api/auth/whoami")
            .get("/quote-api/api/auth/whoami")
            .resources(
                http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/api/quote/getUserDetails/#{rqr_userid}")
                    .get("/quote-api/api/quote/getUserDetails/#{rqr_userid}"),
                http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/api/properties/googleAnalyticsKey")
                    .get("/quote-api/api/properties/googleAnalyticsKey"),
                http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/api/properties/buildInfo")
                    .get("/quote-api/api/properties/buildInfo"),
                http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/v1/user-acknowledgements")
                    .get("/quote-api/v1/user-acknowledgements"),
                http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/api/quote/canAccessQuote/347424ae-4089-4231-ad45-b0160657dfc3")
                    .get("/quote-api/api/quote/canAccessQuote/347424ae-4089-4231-ad45-b0160657dfc3"),
                http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/api/quote/checkPendingFiling/347424ae-4089-4231-ad45-b0160657dfc3")
                    .get("/quote-api/api/quote/checkPendingFiling/347424ae-4089-4231-ad45-b0160657dfc3"),
                http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/api/quote/getCarriersList")
                    .get("/quote-api/api/quote/getCarriersList"),
                http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/v1/quote-form/quote-form/347424ae-4089-4231-ad45-b0160657dfc3")
                    .get("/quote-api/v1/quote-form/quote-form/347424ae-4089-4231-ad45-b0160657dfc3")
                    .check(bodyString().saveAs("BODY"))
                    .exec(session => {
                        val response = session("BODY").as[String];
                        println(s"Response body: \n$response");
                        package$
                    }),

Not sure how to accomplish this and it seems the return value of the “check” does not have a “exec” method. Also, even though I type the work “session” above, after the println, Intellij keeps substituting the word “package$”. Why is this?

Thanks, Timmer

Your exec block must come AFTER the execution of the main HTTP request and its resources.

No idea what your package$ thing is.

Slandelle,
Since there are multiple http requests, particularly when you consider the main http request and then the multiple http requests inside the “.resources” block, how does it pull the value from the response of the single request? Are ALL of the responses (main and resources) cached in some manner? Since you said nothing about the “check…saveAs”, I assume that should stay were it is correct?
Once the “saveAs” happens, how long would the variable, ex…“BODY” be available in the session?
A little unsure about the sessions, does a single session last as long as the virtual users is performing some actions? Even if they are on iteration #20 of the flow the same “session” would exist?

Thanks,
Timmer

A Session is the memory space for a given virtual user. Data stored in there stays as long as you don’t remove it, or the virtual user completes its scenario.

exec(
  http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/api/auth/whoami")
    .get("/quote-api/api/auth/whoami")
    .resources(
      http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/api/quote/getUserDetails/#{rqr_userid}")
        .get("/quote-api/api/quote/getUserDetails/#{rqr_userid}"),
      http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/api/properties/googleAnalyticsKey")
        .get("/quote-api/api/properties/googleAnalyticsKey"),
      http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/api/properties/buildInfo")
        .get("/quote-api/api/properties/buildInfo"),
      http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/v1/user-acknowledgements")
        .get("/quote-api/v1/user-acknowledgements"),
      http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/api/quote/canAccessQuote/347424ae-4089-4231-ad45-b0160657dfc3")
        .get("/quote-api/api/quote/canAccessQuote/347424ae-4089-4231-ad45-b0160657dfc3"),
      http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/api/quote/checkPendingFiling/347424ae-4089-4231-ad45-b0160657dfc3")
        .get("/quote-api/api/quote/checkPendingFiling/347424ae-4089-4231-ad45-b0160657dfc3"),
      http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/api/quote/getCarriersList")
        .get("/quote-api/api/quote/getCarriersList"),
      http("RqrClickStartNewQuote:GET_http://rqr-dev.zic.pri/quote-api/v1/quote-form/quote-form/347424ae-4089-4231-ad45-b0160657dfc3")
        .get("/quote-api/v1/quote-form/quote-form/347424ae-4089-4231-ad45-b0160657dfc3")
        .check(bodyString.saveAs("BODY"))
    ),
  exec(session => {
    val response = session("BODY").as[String];
    println(s"Response body: $response");
    session
  })
)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.