# Inferred Resources

**URL:** <https://community.gatling.io/t/inferred-resources/2294>\
**Category:** Gatling (Open-Source)\
**Created:** [May 15, 2015, 9:58am UTC](https://community.gatling.io/t/inferred-resources/2294 "2015-05-15T09:58:58Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabrizio\_Picca](https://avatars.discourse-cdn.com/v4/letter/f/94ad74/32.png) [@Fabrizio\_Picca](https://community.gatling.io/u/Fabrizio_Picca)\
**Post date:** [May 15, 2015, 9:58am UTC](https://community.gatling.io/t/inferred-resources/2294/1 "2015-05-15T09:58:58Z")

</div>

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

---

<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:** [May 15, 2015, 10:22am UTC](https://community.gatling.io/t/inferred-resources/2294/2 "2015-05-15T10:22:46Z")

</div>

Hi,

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.

Cheers,

---

<div class="post-metadata">

**Author:** ![Fabrizio\_Picca](https://avatars.discourse-cdn.com/v4/letter/f/94ad74/32.png) [@Fabrizio\_Picca](https://community.gatling.io/u/Fabrizio_Picca)\
**Post date:** [May 15, 2015, 10:24am UTC](https://community.gatling.io/t/inferred-resources/2294/3 "2015-05-15T10:24:59Z")

</div>

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).

---

<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:** [May 15, 2015, 10:30am UTC](https://community.gatling.io/t/inferred-resources/2294/4 "2015-05-15T10:30:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Fabrizio\_Picca](https://avatars.discourse-cdn.com/v4/letter/f/94ad74/32.png) [@Fabrizio\_Picca](https://community.gatling.io/u/Fabrizio_Picca)\
**Post date:** [May 15, 2015, 10:33am UTC](https://community.gatling.io/t/inferred-resources/2294/5 "2015-05-15T10:33:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Fabrizio\_Picca](https://avatars.discourse-cdn.com/v4/letter/f/94ad74/32.png) [@Fabrizio\_Picca](https://community.gatling.io/u/Fabrizio_Picca)\
**Post date:** [May 15, 2015, 12:49pm UTC](https://community.gatling.io/t/inferred-resources/2294/6 "2015-05-15T12:49:47Z")

</div>

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: status.find.in(200,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.

---

<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:** [May 15, 2015, 1:37pm UTC](https://community.gatling.io/t/inferred-resources/2294/7 "2015-05-15T13:37:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Fabrizio\_Picca](https://avatars.discourse-cdn.com/v4/letter/f/94ad74/32.png) [@Fabrizio\_Picca](https://community.gatling.io/u/Fabrizio_Picca)\
**Post date:** [May 20, 2015, 2:52pm UTC](https://community.gatling.io/t/inferred-resources/2294/8 "2015-05-20T14:52:42Z")

</div>

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))""", """.*\.css.map""")) .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?

---

<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:** [May 20, 2015, 2:56pm UTC](https://community.gatling.io/t/inferred-resources/2294/9 "2015-05-20T14:56:10Z")

</div>

You can’t build Gatling DSL components at runtime.

---

<div class="post-metadata">

**Author:** ![Fabrizio\_Picca](https://avatars.discourse-cdn.com/v4/letter/f/94ad74/32.png) [@Fabrizio\_Picca](https://community.gatling.io/u/Fabrizio_Picca)\
**Post date:** [May 20, 2015, 3:07pm UTC](https://community.gatling.io/t/inferred-resources/2294/10 "2015-05-20T15:07:07Z")

</div>

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.

Ideas?

---

<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:** [May 20, 2015, 3:10pm UTC](https://community.gatling.io/t/inferred-resources/2294/11 "2015-05-20T15:10:46Z")

</div>

You can access the Session in a transform step, see doc: [http://gatling.io/docs/2.1.6/http/http\_check.html#transforming](http://gatling.io/docs/2.1.6/http/http_check.html#transforming)  
Then, you can’t use EL in here: [http://gatling.io/docs/2.1.6/session/session\_api.html#id2](http://gatling.io/docs/2.1.6/session/session_api.html#id2)

---

<div class="post-metadata">

**Author:** ![Fabrizio\_Picca](https://avatars.discourse-cdn.com/v4/letter/f/94ad74/32.png) [@Fabrizio\_Picca](https://community.gatling.io/u/Fabrizio_Picca)\
**Post date:** [May 21, 2015, 8:12am UTC](https://community.gatling.io/t/inferred-resources/2294/12 "2015-05-21T08:12:41Z")

</div>

Thanks. Ended up in 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))""", “”"._.css.map"""))  
.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],s:Session) =\>  
new HttpTransport(“[http://localhost:8080/data/metrics").doPost(DataEvent("image](http://localhost:8080/data/metrics%22).doPost(DataEvent(%22image)”, s(“imageUrl”).as[String].concat("|").concat(x.length.toString()))) ))

`
