# more checks questions

**URL:** https://community.gatling.io/t/more-checks-questions/416
**Category:** Gatling (Open-Source)
**Created:** [June 5, 2013, 11:19pm UTC](https://community.gatling.io/t/more-checks-questions/416 "2013-06-05T23:19:03Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Shawna](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@Shawna](https://community.gatling.io/u/Shawna)
#### Post date: [June 5, 2013, 11:19pm UTC](https://community.gatling.io/t/more-checks-questions/416/1 "2013-06-05T23:19:03Z")

</div>

Hi:

I found my questions post to this group are always got answered very promptly. Thx for the quick response. Now I have another questions:

I have a scenario that need to send the httprequest first, then parsing the response html: When the html string regex( “”"“content{(\S+)}”"") matchs, it will extract some other substrings StringB from StringA; other wise it will get regex(""“data-object-id=”(\S+)"""") matching from html.

.feed(csv(“messagepool.csv”))  
.exec(http("/message")  
.get("/message/"+ “${messageID}”)  
.check(status.is(200))  
.check(regex("""“content{(\S+)}”"").saveAs(“fullJavascriptObj”))  
.check(regex(""“data-object-id=”(\S+)"""").saveAs(“objectID”))  
.exec((session:Session) =\> {  
doIfOrElse(session.get(“fullJavascriptObj”) != null){  
println(session.get(“fullJavascriptObj”))  
// then do more string manipulations on fullJavascriptObj  
}{  
println(session.get(“objectID”))  
}

But when I run this, if the response html does hot have regex("""“content{(\S+)}”"") matches, it will fail and won’t go on to extract the next one “objectID”. Is there a way to let it do all the extraction? I am using gatling 2.0

Thx  
Shawna

---

<div class="post-metadata">

### Author: ![Nicolas\_R](https://avatars.discourse-cdn.com/v4/letter/n/f14d63/32.png) [@Nicolas\_R](https://community.gatling.io/u/Nicolas_R)
#### Post date: [June 6, 2013, 5:41am UTC](https://community.gatling.io/t/more-checks-questions/416/2 "2013-06-06T05:41:54Z")

</div>

.exec((session:Session) =\> {  
doIfOrElse(session.get(“fullJavascriptObj”) != null){  
println(session.get(“fullJavascriptObj”))  
// then do more string manipulations on fullJavascriptObj  
}{  
println(session.get(“objectID”))  
}

Is this even compiling ?  
You can’t use DSL element inside a .exec() statement as these exec() are made to execute a Scala function.

.exec((session:Session) =\> {  
// I suppose that the type is String … change it if it’s not the case.  
val fullJavascriptObj = session.getAttributeAsOptionString  
if(fullJavascriptObj.isDefined)){  
println(fullJavascriptObj.get)  
// then do more string manipulations on fullJavascriptObj  
} else {  
println(session.get(“objectID”))  
}  
//It is important that the function returns the new Session, it’s a immutable object.  
session  
}

cheers  
Nicolas

---

<div class="post-metadata">

### Author: ![Shawna](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@Shawna](https://community.gatling.io/u/Shawna)
#### Post date: [June 6, 2013, 4:42pm UTC](https://community.gatling.io/t/more-checks-questions/416/3 "2013-06-06T16:42:19Z")

</div>

Thx for the response. My main problem is that I need to check more response body after this. Since I can’t use DSL inside of exec, what should I do: the logic is like below:

> .exec((session:Session) =\> {  
> // I suppose that the type is String … change it if it’s not the case.  
> val fullJavascriptObj = session.getAttributeAsOptionString  
> if(fullJavascriptObj.isDefined)){  
> println(fullJavascriptObj.get)  
> // then do more string manipulations on fullJavascriptObj

> } else {

// i need to get more checks on the response result

---

<div class="post-metadata">

### Author: ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)
#### Post date: [June 6, 2013, 4:58pm UTC](https://community.gatling.io/t/more-checks-questions/416/4 "2013-06-06T16:58:53Z")

</div>

Don’t try to go with the builtin regex support, as it doesn’t match your needs.

Have a bodyString check with a transform step where you’ll code whatever complex logic you want:  
[https://github.com/excilys/gatling/wiki/Checks#wiki-bodyString](https://github.com/excilys/gatling/wiki/Checks#wiki-bodyString)

[https://github.com/excilys/gatling/wiki/Checks#wiki-transforming](https://github.com/excilys/gatling/wiki/Checks#wiki-transforming)

Cheers,

Stéphane

---

<div class="post-metadata">

### Author: ![Shawna](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@Shawna](https://community.gatling.io/u/Shawna)
#### Post date: [June 6, 2013, 9:11pm UTC](https://community.gatling.io/t/more-checks-questions/416/5 "2013-06-06T21:11:24Z")

</div>

Can you add a quick example on how to do that?

like this?

This seems to be not working…  
.check(bodyString).saveAs(“bodyString”)

Also if the document can have more examples on how to use the dsl, that would be greate.

---

<div class="post-metadata">

### Author: ![Shawna](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@Shawna](https://community.gatling.io/u/Shawna)
#### Post date: [June 6, 2013, 9:32pm UTC](https://community.gatling.io/t/more-checks-questions/416/6 "2013-06-06T21:32:02Z")

</div>

Find an example from previous post, seems like this work to get the bodyString saved into a session variable for later processing:

.check(bodyString.transform(string =\> string).saveAs(“a”))

---

<div class="post-metadata">

### Author: ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)
#### Post date: [June 7, 2013, 12:55am UTC](https://community.gatling.io/t/more-checks-questions/416/7 "2013-06-07T00:55:11Z")

</div>

Not exactly. You sure can store the full body String into the Session, but beware that it might increase the chance it survives micro GC and gets promoted to old, thus increase full GC.  
You’d better extract exactly what you want asap with transform.  
If you use regex, beware that it performs substring that, until recent JDK updates, keeps a reference to the original char array, so you might have to make a new String(String).
