Extract JSON from response body

Hello,
I’ using gatling 2.1.7 and I’m blocked by a problem…
I have to extract JSON from a request
I’m new in gatling and scala too, that’s why I need some help

val scn = scenario("Go to Accounts UI")
    .exec(
      http("login")
        .post(siteUrl ++ "/j_spring_security_check")
        .extraInfoExtractor(
          extra =>
            List(s" REQUEST:${extra.requestName}", s"KS:${extra.request.getCookies}", s"HEADERS:${extra.request.getHeaders}", s"URL:${extra.request.getUrl}")
        )
        .basicAuth("user", "administrator")
        .check(status.is(200).saveAs("some"))
        .check(currentLocation
        .transform(s => {
          val regex = ("jsessionid=\\w+").r
          (regex findFirstIn s).get.split("=").get(1)
        })
          .saveAs("sid"))
    ).pause(5)
    .feed(utcFeeder)
    .feed(feeder)
      //.exec(addCookie(Cookie("Set-Cookie", "${sid}")))
    .exec(session => {addCookie(Cookie("JSESSIONID", "${sid}"))
    session.set("","")})
    .exec(http("Search PU")
//    .get("/${sid}/")

      .get(siteUrl + "/some/url")
      .header(HttpHeaderNames.Accept, HttpHeaderValues.ApplicationJson)
      .extraInfoExtractor(extra =>
        List(s" RECVEST2:${extra.requestName}", s"KUKUISS2:${extra.request.getCookies}", s"HEDERS2:${extra.request.getHeaders}", s"URILI2:${extra.request.getUrl}")
      )
      .extraInfoExtractor(
        extraInfo =>
          List(
            extraInfo.requestName,
            s"\nGeneral Response:\r\n${extraInfo.response}",
            s"\nExists??:\r\n${extraInfo.response.hasResponseBody}",

            s"\nResponse Body:\r\n${extraInfo.response.body.string}"
          )
      )
      .body(StringBody( """{"SourceSubscriberIdentifier":"${sourcesubscriberidentifier}"}"""))
      .asJSON
      .headers(headers_14)
      .check(jsonPath("$.success")
        .saveAs("myResponse"))
    )
    .exec(session => {
      println(session.get("myResponse"))
      session
    }
   )

  setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

The result is:

REquEST:login   KS:[JSESSIONID=1DC3179CCDADD5503A0CBDB6C170D811; path=/enr/; HTTPOnly]    HEADERS:    URL:http://localhost:8080/enr/logon/logon.jsp;jsessionid=1DC3179CCDADD5503A0CBDB6C170D811?logon_error=

jsonPath($.success).find(0).exists failed, could not prepare: Could not parse response into a JSON object: Unable to determine the current character, it is not a string, number, array, or object  The current character read is '<' with an int value of 60 Unable to determine the current character, it is not a string, number, array, or object line number 4 index number 6 <html>  ^

What am I doing wrong that I don't have Acsess

Thank you!
.exec(session => {addCookie(Cookie("JSESSIONID", "${sid}"))
    session.set("","")})

Wrong addCookie usage. addCookie is supposed to be directly chained with exec, it’s an action.

jsonPath($.success).find(0).exists failed, could not prepare: Could not parse response into a JSON object: Unable to determine the current character, it is not a string, number, array, or object  The current character read is '<' with an int value of 60 Unable to determine the current character, it is not a string, number, array, or object line number 4 index number 6 <html>  ^

is pretty obvious: the is not proper JSON but HTML. Even if your application rejects this request because of a missing cookie, REST APIs should ALWAYS answer with JSON, not HTML.

Thank you, good to know about this wrong usage…
I tried and with
.exec(addCookie(Cookie(“Set-Cookie”, “${sid}”)))
before, and I commented that trying to find a solution.

And yes, I sow this HTML, that’s why I’m asking you for help…
The sessionId is the right one, but it still not seeing the response body, is saying that I don’t have permissions, the credentials are correct and status after login is 200
Thank you

Response Body:        <html>  <head>      <title>Access Denied!</title>  </head>