Inferred Resources

Hello everybody!
is there any way to store static html resources (or at least get a reference to them) inferred in a gatling scenario?


Try using a currentLocation check for getting the url, or a bodyString or BodyBytes one to get the content.
Then use a transform step to store wherever you want.


But does this method work also with “automatically” inferred resources?
I don’t know the resources that are going to be loaded in advance (they are generated dynamically).

You can define global checks directly on the HttpProtocol so they are used on every request. I think this should also work for inferred ones.
That’s the only solution I can think of.

Thanks a lot, I’ll give it a try!

Hello Stephane,
I think I’m on the right direction after your suggestion, anyway I faced a strange issue and before submitting a bug I’d like to know your opinion.
I found out to have some image urls generated with spaces (my fault, soon to be fixed) anyway I expected Gatling to urlencode also inferred resources urls but this apparently is not happening:

2015-05-15 14:29:24.634 INFO 8828 — [ Thread-11] c.a.e.t.ptl.process.GatlingProcess : 14:29:24.607 [WARN ] i.g.h.a.AsyncHandlerActor - Request yaddayadda-eau de parfum for her-YADDA YADDAYADDA.jpg’ failed:,304,201,202,203,204,205,206,207,208,209), but actually found 505

I found in the documentation that, by default gatling should urlencode url components, but this seems not happening for inferred html resources.

Interesting. Would it be possible for you to share a reproducer, please (even privately)?

In the meanwhile I fixed the code in my app in order to have proper urls.
now I’m trying to do something like this:

val HTTP_PROTOCOL_END_USER_METRICS = http .baseURL("http://" + SERVER) .inferHtmlResources(BlackList(""".*\.?(js|css)(\?v=([0-9]*|[0-9]*\.[0-9]*))?"""), WhiteList(""".*\.(jpg|JPG|jpeg|gif|ico|png|map|PNG|woff|((t|o)tf))""", """.*\""")) .acceptHeader("image/png,image/*;q=0.8,*/*;q=0.5") .acceptEncodingHeader("gzip, deflate") .acceptLanguageHeader("en-US,en;q=0.5") .connection("keep-alive") .contentTypeHeader("application/x-www-form-urlencoded") .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Firefox/24.0") .check( currentLocation.transform( s => { s.replaceFirst("""(/\d+)/[^/]+(\.\w+)""", "$1$2") }).saveAs("imageUrl"), bodyBytes.transform { x: Array[Byte] => { exec(session => { new HttpTransport("http://localhost:8080/data/metrics").doPost(DataEvent("image", "${imageUrl}:" + x.length)) session }) } })

the idea is, for each inferred resouce, to call a rest webservice sending a DataEvent. Unfortunately the session function doesn’t triggers.

Am I doing something wrong?

You can’t build Gatling DSL components at runtime.

Any workaround to achieve something similar?
the real point is how to put together the information coming from the inferred resources in order to send them to an external service.
If everything were inside the same check (for instance bodyBytes, I could easily trigger my post from there) but given that one info (the resource url) comes from another check (currentLocation) I have to store it in the session in order to retrieve it later.


You can access the Session in a transform step, see doc:
Then, you can’t use EL in here:

Thanks. Ended up in something like this:


.baseURL(“http://” + SERVER)
.inferHtmlResources(BlackList("""..?(js|css)(?v=([0-9]|[0-9].[0-9]))?"""), WhiteList("""..(jpg|JPG|jpeg|gif|ico|png|map|PNG|woff|((t|o)tf))""", “”""""))
.acceptEncodingHeader(“gzip, deflate”)
.userAgentHeader(“Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Firefox/24.0”)
s => {
s.replaceFirst("""(/\d+)/[^/]+(.\w+)""", “$1$2”)
bodyBytes.transform((x:Array[Byte],s:Session) =>
new HttpTransport(“http://localhost:8080/data/metrics").doPost(DataEvent("image”, s(“imageUrl”).as[String].concat("|").concat(x.length.toString()))) ))