jsonPath woes

Hi,

I have the JSON below returned from a Restful call, when I use JSONPath tool, I can extract the values I need via:

$…searchResults.file[*].link[0].$

giving me:

[
http://url1/dv/api/user/id/repository/repo/file?path=%2Fbeans-07.jpg”,
http://url/dv/api/user/id/repository/repo/file?path=%2Fbeans-07.jpg
]

But I cannot repeat the same with Gatling’s jsonPath, using the following to check the result of my HTTP call.

.check(jsonPath("$…searchResults.file.link[0].$")
.findAll
.saveAs(“userFiles”))

gives the entire link element as results

No protocol.baseURL defined but provided url is relative : {"$":"http://url1/dv/api/user/id/repository/repo/file?path=%2Fbeans-07.jpg”,","@rel":“file”}

. However …searchResults.file.link[0].@rel works fine in returning

[
“file”,
“file”
]

Stumped…

Al

{
“searchResults”: {
@xmlns”: {
“dvi”: “http://internal.x/ns/1.0”,
“$”: “http://y/ns/1.0”,
“a”: “http://z/ns/1.0
},
@totalCount”: “26”,
“link”: {
@rel”: “next”,
“$”: “http://next/next.html
},
“file”: [
{
“link”: [
{
@rel”: “file”,
“$”: “http://url1/dv/api/user/id/repository/repo/file?path=%2Fbeans-07.jpg
}

]
},
{
“link”: [
{
@rel”: “file”,
“$”: “http://url/dv/api/user/id/repository/repo/file?path=%2Fbeans-07.jpg
}
]
}
]
}
}

Hi,

So, you said that you check this expression $…searchResults.file[*].link[0].$
But in the Gatling, scenario, you don’t use the same one, .check(jsonPath("$…searchResults.file.link[0].$")

Could you try again with .check(jsonPath("$…searchResults.file[*].link[0].$") ?

cheers
Nicolas

Hi Sorry, just a typo - it gives the same results:

14:05:00.701 [ERROR] i.g.h.a.HttpRequestAction - No protocol.baseURL defined but provided url is relative : {"$":“http://............","@rel”:“file”}

Al

Which version of Gatling are you using ?

2.0.0-M3a

thought I’d go with the bleeding edge :wink:

We haven’t released the M4 milestone, but we are getting close to it.
Can I ask you to try with the last Snapshot version ? https://oss.sonatype.org/content/repositories/snapshots/io/gatling/highcharts/gatling-charts-highcharts/2.0.0-SNAPSHOT/

The JsonPath part has been rewritten from scratch using our own engine, https://github.com/gatling/jsonpath. We had too many issues like the own you describe. I have checked and your JsonPath expression is correctly resolved with this version.

cheers
Nicolas

Hi Nicolas,

That seems to work, many thanks.

Al

Nicolas, One more quick question about the new SNAPSHOT version I am using.

When I code:

setUp(scn.inject(nothingFor(4 seconds),
                 atOnce(10 users),
                ramp(10 users) over (5 seconds),

I get a:

…not found: value atOnce
16:47:30.720 [ERROR] i.g.a.ZincCompiler$ - atOnce(25 users),
16:47:30.721 [ERROR] i.g.a.ZincCompiler$ - ^

but I seem to be using a 2.x build

?

Alan

Syntax changed.
atOnce => atOnceUsers
ramp => rampUsers

doh… thanks :wink:

Hi, Since I changed to the SNAPSHOT version mentioned above, I have been unable to Log my responses for debugging purposes.

I get this error

15:50:09.965 [ERROR] i.g.a.ZincCompiler$ - /home/alan/devel/gatling/gatling-charts-highcharts-2.0.0-SNAPSHOT/user-files/simulations/pac/ValidateV2.scala:15: value getResponseBody is not a member of io.gatling.http.response.Response
15:50:09.988 [ERROR] i.g.a.ZincCompiler$ - println(“Response Type:” + response.getResponseBody())

for this code:

val httpP = http
.extraInfoExtractor((callId,status,session,request,response) => {

println(“Call:” + callId)
println("URL " + request.getUrl())
println(“Response Type:” + response.getResponseBody())
Nil
})

If I just dump the response object, I can see it is an instance of NettyResponse which seems to have this method?

//'scuse my Java lingo

Alan

We now have our own Response API which is different from the AHC one.
This way, we have a better control on how the chunks are used.

Now, response has a body which is of type ResponseBody:
https://github.com/excilys/gatling/blob/master/gatling-http/src/main/scala/io/gatling/http/response/Response.scala#L48

And ResponseBody has string, stream and bytes methods:
https://github.com/excilys/gatling/blob/master/gatling-http/src/main/scala/io/gatling/http/response/ResponseBody.scala#L87-L91

So, what you need is response.body.string.

Hi,

Thanks for the quick response as always. This worked once I grabbed the latest snapshot.

Al