[GATLING-2.0.0M3A] Reading and setting Cookies

1,442 views
Skip to first unread message

Bruno Vernay

unread,
Oct 29, 2013, 11:21:52 AM10/29/13
to gat...@googlegroups.com
Hello

I have a web site that set a cookie with a path "/access".  But I would like this cookie to be used on path "/".

I tried this code, to read the cookie's value but it doesn't work. I have an exception.


.exec(http("request_Login")
    .post("/access")
    .queryParam("action", "login")
    .body(StringBody("""{"login":"adm","password":"adm"}"""))
    .headers(headers_json)
    )
.pause(1)
.exec( session => {
                import io.gatling.http.cookie._
                import java.net.URI
        
                val ck = session("gatling.http.cookies").as[CookieJar].get(URI.create("//bdist")).find(
                        _.getName == "session-id"
                    )
                session.set("test", ck.getOrElse(null).getValue)
}) 


HTTP response:
status=
202 Accepted
headers= 
content-type: [application/json]
transfer-encoding: [chunked]
date: [Tue, 29 Oct 2013 15:37:27 GMT]
set-cookie: [session-id=a72e12d3-847c-481d-942d-6928c3667c18; HttpOnly]


<<<<<<<<<<<<<<<<<<<<<<<<<
[ERROR] [10/29/2013 15:43:18.885] [GatlingSystem-akka.actor.default-dispatcher-13] [akka://GatlingSystem/user/$i] null
java.lang.NullPointerException
at se.box.browse$$anonfun$1.apply(browse.scala:113)
at se.box.browse$$anonfun$1.apply(browse.scala:106)
at io.gatling.core.action.SessionHook.executeOrFail(SessionHook.scala:35)
at io.gatling.core.action.Failable$class.execute(Actions.scala:82)
at io.gatling.core.action.SessionHook.execute(SessionHook.scala:28)
at io.gatling.core.action.Action$$anonfun$receive$1.applyOrElse(Actions.scala:42)
at scala.PartialFunction$OrElse.applyOrElse(PartialFunction.scala:166)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:425)
at akka.actor.ActorCell.invoke(ActorCell.scala:386)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:230)
at akka.dispatch.Mailbox.run(Mailbox.scala:212)
at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:506)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

15:43:18.926 [ERROR] i.g.c.a.b.SessionHookBuilder$$anonfun$build$1$$anon$1 - Action $anonfun$build$1$$anon$1 crashed, forwarding user to next one
java.lang.NullPointerException: null
at se.box.browse$$anonfun$1.apply(browse.scala:113) ~[na:na]
at se.box.browse$$anonfun$1.apply(browse.scala:106) ~[na:na]
at io.gatling.core.action.SessionHook.executeOrFail(SessionHook.scala:35) ~[gatling-core-2.0.0-M3a.jar:na]
at io.gatling.core.action.Failable$class.execute(Actions.scala:82) ~[gatling-core-2.0.0-M3a.jar:na]
at io.gatling.core.action.SessionHook.execute(SessionHook.scala:28) ~[gatling-core-2.0.0-M3a.jar:na]
at io.gatling.core.action.Action$$anonfun$receive$1.applyOrElse(Actions.scala:42) ~[gatling-core-2.0.0-M3a.jar:na]
at scala.PartialFunction$OrElse.applyOrElse(PartialFunction.scala:166) ~[scala-library-2.10.2.jar:na]
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:425) ~[akka-actor_2.10-2.1.4.jar:na]
at akka.actor.ActorCell.invoke(ActorCell.scala:386) ~[akka-actor_2.10-2.1.4.jar:na]
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:230) ~[akka-actor_2.10-2.1.4.jar:na]
at akka.dispatch.Mailbox.run(Mailbox.scala:212) ~[akka-actor_2.10-2.1.4.jar:na]
at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:506) [akka-actor_2.10-2.1.4.jar:na]
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.10.2.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.10.2.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.10.2.jar:na]
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.10.2.jar:na]
15:43:18.929 [INFO ] i.g.h.a.HttpRequestAction - Sending request 'request_7': scenario 'Scenario Name', userId #0
15:43:19.156 [TRACE] i.g.h.a.AsyncHandlerActor - 
>>>>>>>>>>>>>>>>>>>>>>>>>>
Request:
request_7: OK 
=========================
Session:
Session(Scenario Name,0,Map(gatling.http.cookies -> CookieStore=Map(//bdist -> List(Cookie: domain=bdist, name=session-id, value=a72e12d3-847c-481d-942d-6928c3667c18, path=/access, maxAge=-1, secure=false))),1383057794207,23,List(),List(KO),List(),List())
========================= 

Regards 
Bruno

Bruno Vernay

unread,
Oct 29, 2013, 12:06:51 PM10/29/13
to gat...@googlegroups.com
Well

Unless there is a mean to change the thread title we may better continue on this one ... (sorry for this)

So in the mean time, I found that my domain was wrong: using 
                       val ck = session("gatling.http.cookies").as[CookieJar].get(URI.create("http://bdist/access")).find(
                                _.getName == "session-id"
                            )
                        session.set("test", ck.getOrElse(null).getValue)
worked !

But honestly I have no idea how to use this:
exec(addCookies(url: Expression[String], cookie: Cookie, cookies: Cookie*))

Bruno Vernay

unread,
Oct 30, 2013, 3:47:11 AM10/30/13
to gat...@googlegroups.com
To sum up the discussion about Cookie in 2.0.0
First do not use 2.0.0M3a.  

You may have to:
- Add the libraries: logback- classic and core from previous Gatling lib.
- Remove the examples (compilation errors)

The DSL has changed a bit (simply start with the recorder to get a valid example):
- Remove the imports:  bootstrap._ and  assertions._

Then the code example:
        .exec(http("request_Login")
            .post("/access")
            .queryParam("action", "login")
            .body(StringBody("""{"login":"adm","password":"adm"}"""))
            .headers(headers_json)
            )
        .pause(1)
        .exec( session => {
                    import io.gatling.http.cookie._
                    import java.net.URI
                
                    val ck = session("gatling.http.cookies").as[CookieJar].get(URI.create("http://bdist/access")).find(
                            _.getName == "session-id"
                        )
                    session.set("test", ck.getOrElse(null).getValue)
        }) 
        .exec(
            addCookie("session-id", "${test}")   // Default to path=/
        )

Bruno

Pierre DAL-PRA

unread,
Oct 30, 2013, 4:18:43 AM10/30/13
to gat...@googlegroups.com
The missing Logback dependencies in the bundle was a bug, now fixed :)
Grab the latest bundle from Sonatype snapshots repository and you'll get a fully working bundle !

Envoyé de mon iPhone
--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages