Error : Could not parse content-type: Response does not have a content-type header

5,011 views
Skip to first unread message

Kuzhali Velmurugan

unread,
Sep 27, 2017, 2:12:06 AM9/27/17
to REST assured
Hi,
My test is as below:

@Test(dependsOnMethods = {"shouldCreateMeasurement"})
public void shouldDeleteMeasurement() {
given().header(SESSION_TOKEN, sessionToken)
.contentType("application/json,text/plain")
.header(SECTION, "aaa")
.param("operation", "aaa")
.param("measurementId", guid).log().all()
.delete("/api/dddd/" + guid).then().log().all()
            .assertThat().statusCode(200);
}

The entity gets deleted, but am getting an error message:

Sep 27, 2017 11:33:46 AM com.jayway.restassured.internal.RequestSpecificationImpl$RestAssuredHttpBuilder parseResponse
WARNING: Could not parse content-type: Response does not have a content-type header

com.jayway.restassured.internal.http.ResponseParseException: OK

	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	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:232)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:252)
	at com.jayway.restassured.internal.RequestSpecificationImpl$RestAssuredHttpBuilder.doRequest(RequestSpecificationImpl.groovy:1808)


Anyway to resolve this? 
I have added this in base class :
RestAssured.registerParser("text/plain", Parser.JSON);

Thanks,
Poonkuzhali

Todd Bradley

unread,
Sep 27, 2017, 9:07:57 AM9/27/17
to rest-a...@googlegroups.com
The web service you are testing, is it normal for it to not send a Content-Type header with HTTP responses? To me that seems like a bug in your system under test. 

On the request side, I've never seen a Content-Type that is a comma separated list. Is that legal? Do you mean for "application/json,text/plain" to be an Accepts header instead of a Content-Type header?



--
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/d/optout.
--
Sent from Gmail Mobile

Johan Haleby

unread,
Sep 27, 2017, 3:30:25 PM9/27/17
to rest-a...@googlegroups.com
What Todd says about the Accept header is probably right but REST Assured should not require to know the content-type if no assertions are made to body. Please try the same example with the latest version to see if the problems persists.

To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Sent from Gmail Mobile

--
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+unsubscribe@googlegroups.com.

Kuzhali Velmurugan

unread,
Sep 28, 2017, 5:03:32 AM9/28/17
to REST assured
Sorry that I added by mistake (application/json,text/plain) while trying out different combinations to get it to work as error was related to content type. Actual request  doesn't require Content Type and also the url params (tried from postman), the entity is deleted when checked in Db, but we see error as stated above. The same call passes when guid is hard coded.

public void shouldDeleteMeasurement() {
given().header(SESSION_TOKEN, sessionToken)
            .header(SECTION, "demo").log().all()
.delete("/api/AAA/" + guid).then().log().all()
.assertThat().statusCode(200);
}

The gradle version that I have been using is 2.12 and rest assured is the older one 2.4.1.

As Johan said, I will try to upgrade it to latest version of Rest Assured.

Thank you,
Poonkuzhali

Kuzhali Velmurugan

unread,
Sep 28, 2017, 5:41:43 AM9/28/17
to REST assured
Thank you Todd and Johan :) Upgrading to latest version of Rest Assured solved the issue.

Johan Haleby

unread,
Sep 28, 2017, 5:50:27 AM9/28/17
to rest-a...@googlegroups.com
Great! Thanks for sharing.

To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages