new member to Rest assured: need help on cookies and body

451 views
Skip to first unread message

svk Krishna

unread,
Feb 6, 2014, 3:53:56 AM2/6/14
to rest-a...@googlegroups.com
Hi All,

I am facing problem when i run following script, which is returning status code as 401.

public class Test_RestAssured {
@Test
public static void test(){
String body = given()
                .header("Accept", "application/json")
                .cookie("IMTicketId", "cf30bdd3550a16c573bca9266851ea45456e93f1aad9c12c80dca0054a52f300ddb4e7b3c1bb1bc4b49780abb7d978e260bb519ccb57bfe0b3316ade8f87afbbffbe01fa1d1c425e4b40d2239bb0ab7954abe6d836e0e2f2c66fc3a2fe52ac474a23a523da25a02cc4f0f3799d0b14707425f789d1e4d9c2441cefc19910bc49157f9c4a8c35f5c91475789da41f12e8babf7723a4c34957a79844c3fdb0405f46f47033018654e7279a186c4c25b5674a0cfd06d6db5e37b40f2851d575373a")
                .cookie("IMSessionId", "fe755172-3f94-4599-9d94-07d8b79da969")
                .cookie("IMIV", "a776b849501cdc0eb78a4cfa11fe4a97")
                .expect()
                .statusCode(200)
           
                .when()
                .get("https://stage3.test.com/services/api/v1/product")
                .prettyPrint();
// System.out.println("body");

}

}

when i use the same thing in fidler its returning valid json with status code 200. and please help to add asserts, verifying body.

Thanks in advance.

Thanks
Vamsi

Johan Haleby

unread,
Feb 6, 2014, 4:20:08 AM2/6/14
to rest-a...@googlegroups.com
Could you log the response so that we can see what it looks like?


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

svk Krishna

unread,
Feb 6, 2014, 5:46:05 AM2/6/14
to rest-a...@googlegroups.com
[TestNG] Running:
  C:\Users\autolab\AppData\Local\Temp\testng-eclipse-163501045\testng-customsuite.xml

FAILED: test
java.lang.AssertionError: 1 expectation failed.
Expected status code <200> doesn't match actual status code <404>.

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:71)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:81)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)
at com.jayway.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure.validate(ResponseSpecificationImpl.groovy:557)
at com.jayway.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure$validate$1.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at com.jayway.restassured.internal.RequestSpecificationImpl.invokeFilterChain(RequestSpecificationImpl.groovy:868)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:730)
at com.jayway.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)
at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)
at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:55)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
at com.jayway.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1282)
at com.jayway.restassured.internal.RequestSpecificationImpl.this$2$applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:730)
at com.jayway.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)
at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)
at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:55)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
at com.jayway.restassured.internal.RequestSpecificationImpl.get(RequestSpecificationImpl.groovy:140)
at com.jayway.restassured.internal.RequestSpecificationImpl.get(RequestSpecificationImpl.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:730)
at com.jayway.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)
at org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at com.jayway.restassured.internal.ResponseSpecificationImpl.get(ResponseSpecificationImpl.groovy:264)
at com.jayway.restassured.internal.ResponseSpecificationImpl.get(ResponseSpecificationImpl.groovy)
at Test_RestAssured.test(Test_RestAssured.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)


Thanks
Vamsi

On Thursday, February 6, 2014 2:50:08 PM UTC+5:30, Johan Haleby wrote:
Could you log the response so that we can see what it looks like?
On Thu, Feb 6, 2014 at 9:53 AM, svk Krishna <vso...@gmail.com> wrote:
Hi All,

I am facing problem when i run following script, which is returning status code as 404.

public class Test_RestAssured {
@Test
public static void test(){
String body = given()
                .header("Accept", "application/json")
                .cookie("IMTicketId", "cf30bdd3550a16c573bca9266851ea45456e93f1aad9c12c80dca0054a52f300ddb4e7b3c1bb1bc4b49780abb7d978e260bb519ccb57bfe0b3316ade8f87afbbffbe01fa1d1c425e4b40d2239bb0ab7954abe6d836e0e2f2c66fc3a2fe52ac474a23a523da25a02cc4f0f3799d0b14707425f789d1e4d9c2441cefc19910bc49157f9c4a8c35f5c91475789da41f12e8babf7723a4c34957a79844c3fdb0405f46f47033018654e7279a186c4c25b5674a0cfd06d6db5e37b40f2851d575373a")
                .cookie("IMSessionId", "fe755172-3f94-4599-9d94-07d8b79da969")
                .cookie("IMIV", "a776b849501cdc0eb78a4cfa11fe4a97")
                .expect()
                .statusCode(200)
           
                .when()
                .get("https://stage3.test.com/services/api/v1/product")
                .prettyPrint();
// System.out.println("body");

}

}

when i use the same thing in fidler its returning valid json with status code 200. and please help to add asserts, verifying body.

Thanks in advance.

Thanks
Vamsi

svk Krishna

unread,
Feb 6, 2014, 6:24:10 AM2/6/14
to rest-a...@googlegroups.com
sorry, i thought i've already posted my logs:

Johan Haleby

unread,
Feb 6, 2014, 6:41:47 AM2/6/14
to rest-a...@googlegroups.com
I meant logging the HTTP response.

/Johan


thanks
Vamsi

On Thursday, February 6, 2014 2:50:08 PM UTC+5:30, Johan Haleby wrote:

svk Krishna

unread,
Feb 6, 2014, 9:09:27 AM2/6/14
to rest-a...@googlegroups.com
here is http response:


HTTP/1.1 404 Not Found
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.5
Access-Control-Allow-Origin: *
Access-Control-Request-Method: *
Access-Control-Request-Headers: *
Access-Control-Allow-Headers: accept, imauthid, origin, imiv, imticketid, Content-Type
Access-Control-Allow-Methods: *
Date: Thu, 06 Feb 2014 13:56:51 GMT
Content-Length: 231

{
    "$id": "1",
    "Message": "No HTTP resource was found that matches the request URI 'http://stage3.test.com:81/services/api/v1/product'.",
    "MessageDetail": "No type was found that matches the controller named 'product'."
}

This service will give response only on https. Kinldy help me to resolve this issue.

Thanks
Vamsi

svk Krishna

unread,
Feb 7, 2014, 10:45:28 AM2/7/14
to rest-a...@googlegroups.com
Johan... Any Suggestions please.

Thanks
Vamsi

Johan Haleby

unread,
Feb 9, 2014, 9:59:48 AM2/9/14
to rest-a...@googlegroups.com
You seem to have an invalid certificate. Use given().relaxedHTTPSValidation().when().get("https://stage3.test.com/services/api/v1/product"). .. 

/Johan

svk Krishna

unread,
Feb 9, 2014, 12:16:21 PM2/9/14
to rest-a...@googlegroups.com
Hi Johan,

Thanks for your reply. i am getting first error message (i.e. No type was found that matches the controller named 'product'.) after adding relaxedHTTPvalidation to my script.

Kindly help me to fix below script and let me know if i need to make any changes to get it worked.
<script>

public class Test_RestAssured {

@Test

public static void test(){

String body = given()

.port(443)

.keystore("c:/users/autolab/truststore_javanet.jks", "abcdef")

.relaxedHTTPSValidation()

                .header("Accept", "application/json", "ImAuthId", "10000155408")

                .header("IMTicketId", "e95c9ebcc435e7aa9d8d46ffd5d1345408764a98aa7e3d6b43d30d0cfa68d937e13392c99105b1e92c1b2a6abb5ee6ca3a0c61f4d2e440c0a925724aeb8ab3fb2772cbb49d27d6a1e36219dfdb122005c9fef0b1564c183a2f8f532ad39668065dd12e1b3056e3a613beba523e97a5f45f698d45b9620ef93906926883b2742cac9d2c9ff5a40ec48f81f40390aa3d3a08c53cec2de0d250368eaf8c962b90764011c982334f73ed332d950378cccd88f8076ee937aa75674a36e1b9f761cc36")

                .header("IMIV", "54112aeb8006cce4b800033c1d4efed5")


                .expect()

                .log().all()

                .statusCode(200)

           

                .when()

                .get("https://stage.test.com/services/api/v1/product")

                .prettyPrint();


}


}



<output:>


[TestNG] Running:

  C:\Users\autolab\AppData\Local\Temp\testng-eclipse-1245883309\testng-customsuite.xml


HTTP/1.1 404 Not Found

Cache-Control: no-cache

Pragma: no-cache

Content-Type: application/json; charset=utf-8

Expires: -1

Server: Microsoft-IIS/7.5

Access-Control-Allow-Origin: *

Access-Control-Request-Method: *

Access-Control-Request-Headers: *

Access-Control-Allow-Headers: accept, imauthid, origin, imiv, imticketid, Content-Type

Access-Control-Allow-Methods: *

Date: Sun, 09 Feb 2014 17:02:09 GMT

Content-Length: 228


{

    "$id": "1",

    "Message": "No HTTP resource was found that matches the request URI 'https://stage.test.com/services/api/v1/product'.",

    "MessageDetail": "No type was found that matches the controller named 'product'."

}

FAILED: test

java.lang.AssertionError: 1 expectation failed.

Expected status code <200> doesn't match actual status code <404>.



Thanks
Vamsi

Johan Haleby

unread,
Feb 10, 2014, 2:50:03 AM2/10/14
to rest-a...@googlegroups.com
One thing is that you don't need to define the keystore when you're using relaxed https validation and do you really mean to add a multi-value header like this: header("Accept", "application/json", "ImAuthId", "10000155408")? Seems really strange. Please read the javadoc and see documentation.

When I make a call to "https://stage.test.com/services/api/v1/product" with relaxed https validation I don't get 404 back.

/Johan
Reply all
Reply to author
Forward
0 new messages