djangid / rest-assured

Automatically exported from code.google.com/p/rest-assured
0 stars 0 forks source link

Getting ResponseParseException "No such field: CONTENT_TYPE" when getting JSON response without content-type header #253

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Add RestAssured.defaultParser = Parser.JSON; since response does not contain 
content-type header
2. Send get request
        given().
        .header("X-Accept-Version", "2.0")
        .expect().statusCode(200)
        .when().get("/catalog");

What is the expected output? What do you see instead?

I expect to get success on the test. The response contains JSON object. 

Actual result - getting following exception even though I have all the 
dependencies from the zip file in place and recreated test project from scratch 
using only supplied jars. Without setting default parser I'm getting just 
warning "WARNING: Could not parse content-type: Response does not have a 
content-type header".

Aug 05, 2013 10:27:24 PM com.jayway.restassured.internal.http.HTTPBuilder 
parseResponse
WARNING: Could not parse content-type: No such field: CONTENT_TYPE for class: 
com.jayway.restassured.internal.RequestSpecificationImpl$RestAssuredHttpBuilder
FAILED: getCatalog
com.jayway.restassured.internal.http.ResponseParseException: OK
    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:526)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
    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:194)
    at com.jayway.restassured.internal.RequestSpecificationImpl$RestAssuredHttpBuilder.doRequest(RequestSpecificationImpl.groovy:1400)
    at com.jayway.restassured.internal.http.HTTPBuilder.doRequest(HTTPBuilder.java:490)
    at com.jayway.restassured.internal.http.HTTPBuilder.request(HTTPBuilder.java:439)
    at com.jayway.restassured.internal.http.HTTPBuilder$request.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:124)
    at com.jayway.restassured.internal.RequestSpecificationImpl.sendHttpRequest(RequestSpecificationImpl.groovy:953)
    at com.jayway.restassured.internal.RequestSpecificationImpl.this$2$sendHttpRequest(RequestSpecificationImpl.groovy)
    at com.jayway.restassured.internal.RequestSpecificationImpl$this$2$sendHttpRequest.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at com.jayway.restassured.internal.RequestSpecificationImpl.sendRequest(RequestSpecificationImpl.groovy:820)
    at com.jayway.restassured.internal.RequestSpecificationImpl.this$2$sendRequest(RequestSpecificationImpl.groovy)
    at com.jayway.restassured.internal.RequestSpecificationImpl$this$2$sendRequest.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:124)
    at com.jayway.restassured.internal.filter.RootFilter.filter(RootFilter.groovy:30)
    at com.jayway.restassured.filter.Filter$filter.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:124)
    at com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:49)
    at com.jayway.restassured.filter.FilterContext$next.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:120)
    at com.jayway.restassured.internal.RequestSpecificationImpl.invokeFilterChain(RequestSpecificationImpl.groovy:758)
    at com.jayway.restassured.internal.RequestSpecificationImpl$invokeFilterChain.callCurrent(Unknown Source)
    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:1142)
    at com.jayway.restassured.internal.RequestSpecificationImpl.this$2$applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy)
    at com.jayway.restassured.internal.RequestSpecificationImpl$this$2$applyPathParamsAndSendRequest.callCurrent(Unknown Source)
    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:131)
    at com.jayway.restassured.specification.RequestSender$get.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:120)
    at com.jayway.restassured.internal.ResponseSpecificationImpl.get(ResponseSpecificationImpl.groovy:226)
    at motif.qa.rest.assured.GetExample.getCatalog(GetExample.java:27)
    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:606)
    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:335)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
    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)
Caused by: groovy.lang.MissingFieldException: No such field: CONTENT_TYPE for 
class: 
com.jayway.restassured.internal.RequestSpecificationImpl$RestAssuredHttpBuilder
    at groovy.lang.MetaClassImpl.getAttribute(MetaClassImpl.java:2577)
    at groovy.lang.MetaClassImpl.getAttribute(MetaClassImpl.java:3416)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getGroovyObjectField(ScriptBytecodeAdapter.java:352)
    at com.jayway.restassured.internal.RequestSpecificationImpl$RestAssuredHttpBuilder.this$dist$get$2(RequestSpecificationImpl.groovy)
    at com.jayway.restassured.internal.RequestSpecificationImpl$RestAssuredHttpBuilder$1.propertyMissing(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:606)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaClassImpl.invokeMissingProperty(MetaClassImpl.java:778)
    at groovy.lang.MetaClassImpl$12.getProperty(MetaClassImpl.java:1845)
    at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.callGroovyObjectGetProperty(GetEffectivePogoPropertySite.java:67)
    at com.jayway.restassured.internal.RequestSpecificationImpl$RestAssuredHttpBuilder$1.getContentType(RequestSpecificationImpl.groovy:1443)
    at com.jayway.restassured.internal.http.HttpResponseContentTypeFinder.findContentType(HttpResponseContentTypeFinder.java:34)
    at com.jayway.restassured.internal.http.HttpResponseDecorator.getContentType(HttpResponseDecorator.java:87)
    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:606)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at org.codehaus.groovy.runtime.metaclass.MethodMetaProperty$GetBeanMethodMetaProperty.getProperty(MethodMetaProperty.java:73)
    at org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:61)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)
    at com.jayway.restassured.internal.RestAssuredResponseImpl.parseContentType(RestAssuredResponseImpl.groovy:85)
    at com.jayway.restassured.internal.RestAssuredResponseImpl$parseContentType.callCurrent(Unknown Source)
    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:141)
    at com.jayway.restassured.internal.RestAssuredResponseImpl.parseResponse(RestAssuredResponseImpl.groovy:65)
    at com.jayway.restassured.internal.RestAssuredResponseImpl$parseResponse.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:128)
    at com.jayway.restassured.internal.ResponseSpecificationImpl$_HamcrestAssertionClosure_getClosure_closure1.doCall(ResponseSpecificationImpl.groovy:375)
    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:606)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
    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.RequestSpecificationImpl$RestAssuredHttpBuilder.doRequest(RequestSpecificationImpl.groovy:1395)
    ... 69 more

===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================

===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

What version of the product are you using? On what operating system?
rest-assured 1.8.1 and all the dependencies supplied with the zip
json-path 1.8.1 and all the dependencies supplied with the zip

Running in Eclipse with testng on MacOS and JDK 7

Original issue reported on code.google.com by fila...@gmail.com on 6 Aug 2013 at 5:38

GoogleCodeExporter commented 8 years ago
Hi, 

I don't suppose you could try out the same thing when you're using the Maven 
instead to see if you get the same error?

Regards,
/Johan

Original comment by johan.ha...@gmail.com on 9 Oct 2013 at 5:10

GoogleCodeExporter commented 8 years ago
Same problem here. Version 1.8.1 with Maven and Intellij...

given().header("Content-Type", "text/plain")

(trying setting manually the header, because the
given().contentType(ContentType.TEXT)
not add the content-type header in the request...)

Original comment by bonfante...@gmail.com on 6 Nov 2013 at 2:12

GoogleCodeExporter commented 8 years ago
Digging in the source code, seems the rest-assured try to "survive" if the 
server doesn't provide a content-type for the response. 
I've verified the response of my jersey-server and noticed the missing 
content-type (specifically while mapping an exception).
Adding the content-type header in the response avoid this exception.

Original comment by bonfante...@gmail.com on 6 Nov 2013 at 2:55

GoogleCodeExporter commented 8 years ago

Original comment by johan.ha...@gmail.com on 12 Nov 2013 at 7:28

GoogleCodeExporter commented 8 years ago
I've now spent 3 hours trying to make Jersey send a response without a content 
type so that I can verify the error. How do you manage to get Jersey to do this?

Original comment by johan.ha...@gmail.com on 12 Nov 2013 at 10:07

GoogleCodeExporter commented 8 years ago
I've also tried to provide a fix, but I haven't been able to test it so please 
verify that it works by building Rest Assured from the latest master.

Original comment by johan.ha...@gmail.com on 12 Nov 2013 at 10:16

GoogleCodeExporter commented 8 years ago
I'm with jersey 2.3.1 mapping an exception something like this: 
http://howtodoinjava.com/2013/06/03/exception-handling-in-jax-rs-resteasy-with-e
xceptionmapper/.
Jersey didn't set the content-type automatically in this case, so I've set the 
header response manually. Maybe an updated jersey version behave differently... 
I don't know.

Original comment by bonfante...@gmail.com on 12 Nov 2013 at 11:40

GoogleCodeExporter commented 8 years ago
I've uploaded a new snapshot version to sonatype now, please depend on 
1.8.2-SNAPSHOT after having added the following maven repo to see if it works:

<repositories>
        <repository>
            <id>sonatype</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <snapshots />
        </repository>
</repositories>

Original comment by johan.ha...@gmail.com on 12 Nov 2013 at 2:48

GoogleCodeExporter commented 8 years ago
Thanks, I'll give a try when I can.

Original comment by bonfante...@gmail.com on 12 Nov 2013 at 5:11

GoogleCodeExporter commented 8 years ago
I'll consider this fixed, please re-open if you experience the same problem 
(please try to test it asap since I want to make a new release soon).

Original comment by johan.ha...@gmail.com on 14 Nov 2013 at 9:09