sending the last JSESSIONID cookie to next rest call

3,136 views
Skip to first unread message

yousef baba

unread,
Oct 31, 2013, 9:50:21 AM10/31/13
to rest-a...@googlegroups.com
hi

i am trying to get the last SESSIONID cookie to next rest call, used  RestAssured.config in order to make this working but i don't see that this effect the rest call i am using.

i tried it with rest-assuured version 1.6.2 and 1.8.1.

what i am doing wrong ?


here is my code:
 RestAssured.config = newConfig().sessionConfig(new SessionConfig().sessionIdName("JSESSIONID"));

Response r = RestAssured.given().log().all().auth().preemptive() .basic("username", "password").body(json) .header("Content-Type", "application/json") .header("X-CSRF-HPMEAP", "FROM-DESKTOP").expect() .statusCode(200).response().post(path); System.out.println(r.getCookies()); r = RestAssured.given().log().all().expect().get(path);

Johan Haleby

unread,
Nov 1, 2013, 5:40:00 PM11/1/13
to rest-a...@googlegroups.com
Hi,

You need to extract the cookie from the original reponse and use it in the next one. Something like:

String sessionId = given().auth().preemptive().basic("username", "password").when().post("/x").andReturn().sessionId();

given().sessionId(sessionId).when().post("/y");
given().sessionId(sessionId).when().post("/z");

You could also create a filter to handle this transparently.

Regards
/Johan 


--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

yousef baba

unread,
Nov 3, 2013, 7:20:20 AM11/3/13
to rest-a...@googlegroups.com
Thanks for you answer, but my problem is that sometimes after some rest calls tomcat will change SESSIONID and i don't know when this happens.
there must be a way that rest-assured recognize that JSESSIONID is changed and send it back.
any idea ?

Johan Haleby

unread,
Nov 4, 2013, 4:58:33 AM11/4/13
to rest-a...@googlegroups.com
No REST Assured doesn't do this automatically but you could easily write a filter that does this for you.

/Johan


yousef baba

unread,
Nov 4, 2013, 7:03:25 AM11/4/13
to rest-a...@googlegroups.com
can you please help me with filter ??
i tried to implement it with filter but without success.


On Thursday, October 31, 2013 3:50:21 PM UTC+2, yousef baba wrote:

Johan Haleby

unread,
Nov 4, 2013, 7:20:46 AM11/4/13
to rest-a...@googlegroups.com
Maintain the sessionid of the response as a field in the filter and use that in the subsequent requests. If you always override the value of in the field holding the sessionid in the filter then you'll always use the latest value in the subsequent request(s).


Reply all
Reply to author
Forward
0 new messages