ClientProtocolException occurs on Put operation with zero content

1,559 views
Skip to first unread message

Jeff M

unread,
Apr 12, 2013, 6:07:04 PM4/12/13
to rest-a...@googlegroups.com
Hi,

I am using REST assured to test against a vendor's REST interface.  There is a particular operation that requires submitting some custom headers via a PUT operation with a zero content length body.  When I attempt to do this, no message is transmitted and I encounter an org.apache.http.client.ClientProtocolException,  I believe that I narrowed it down to the presence of the Content-Type=*/* header which I think is being injected automatically by REST assured.  I came to this conclusion by coding the REST call directly using Apache HTTP client and the call acted as expected. Additionally, I used WireShark to verify that the HttpClient code was not transmitting Content-Type, and that it was transmitting Content-Length: 0.  Is there a way to prohibit the Content-Type header from being submitted?  Below I included the REST assured code that threw the exception, the HttpClient code that was successful, and lastly the stack trace.

Thanks,

Jeff

REST assured code
        response = RestAssured.
                with().
                    log().all().
                    header("customHeader1", "SomeValue1").
                    header("customHeader2", "SomeValue2").
                    header("Content-Length", "0").
                expect().
                    log().all().
                    statusCode(201).
                when().
                    put(url);
Apache Http Client code
        AbstractHttpClient httpClient = new DefaultHttpClient();
        HttpPut httpPut = new HttpPut(url);
        httpPut.addHeader("customHeader1", "SomeValue1");
        httpPut.addHeader("customHeader2", "SomeValue2");
       
        HttpResponse httpResponse = null;
        httpResponse = httpClient.execute(httpPut);

        int statusCode = httpResponse.getStatusLine().getStatusCode();
        assertThat(statusCode, equalTo(HttpStatus.SC_CREATED));

Stack Trace
org.apache.http.client.ClientProtocolException
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:909)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
    at org.apache.http.client.HttpClient$execute.call(Unknown Source)
    at com.jayway.restassured.internal.RequestSpecificationImpl$RestAssuredHttpBuilder.doRequest(RequestSpecificationImpl.groovy:1350)
    at com.jayway.restassured.internal.http.HTTPBuilder.doRequest(HTTPBuilder.java:489)
    at com.jayway.restassured.internal.http.HTTPBuilder.request(HTTPBuilder.java:438)
    at com.jayway.restassured.internal.http.HTTPBuilder$request.call(Unknown Source)
    at com.jayway.restassured.internal.RequestSpecificationImpl.sendHttpRequest(RequestSpecificationImpl.groovy:926)
    at com.jayway.restassured.internal.RequestSpecificationImpl.this$2$sendHttpRequest(RequestSpecificationImpl.groovy)
    at com.jayway.restassured.internal.RequestSpecificationImpl$this$2$sendHttpRequest.callCurrent(Unknown Source)
    at com.jayway.restassured.internal.RequestSpecificationImpl.sendRequest(RequestSpecificationImpl.groovy:793)
    at com.jayway.restassured.internal.RequestSpecificationImpl.this$2$sendRequest(RequestSpecificationImpl.groovy)
    at com.jayway.restassured.internal.RequestSpecificationImpl$this$2$sendRequest.call(Unknown Source)
    at com.jayway.restassured.internal.filter.RootFilter.filter(RootFilter.groovy:28)
    at com.jayway.restassured.filter.Filter$filter.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at com.jayway.restassured.filter.Filter$filter$0.call(Unknown Source)
    at com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:47)
    at com.jayway.restassured.filter.log.StatusCodeBasedLoggingFilter.filter(StatusCodeBasedLoggingFilter.java:95)
    at com.jayway.restassured.filter.log.ResponseLoggingFilter.filter(ResponseLoggingFilter.java:31)
    at com.jayway.restassured.filter.Filter$filter$0.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at com.jayway.restassured.filter.Filter$filter$0.call(Unknown Source)
    at com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:47)
    at com.jayway.restassured.filter.log.RequestLoggingFilter.filter(RequestLoggingFilter.java:134)
    at com.jayway.restassured.filter.Filter$filter$0.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at com.jayway.restassured.filter.Filter$filter.call(Unknown Source)
    at com.jayway.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:47)
    at com.jayway.restassured.filter.FilterContext$next.call(Unknown Source)
    at com.jayway.restassured.internal.RequestSpecificationImpl.invokeFilterChain(RequestSpecificationImpl.groovy:731)
    at com.jayway.restassured.internal.RequestSpecificationImpl$invokeFilterChain.callCurrent(Unknown Source)
    at com.jayway.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1115)
    at com.jayway.restassured.internal.RequestSpecificationImpl.this$2$applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy)
    at com.jayway.restassured.internal.RequestSpecificationImpl$this$2$applyPathParamsAndSendRequest.callCurrent(Unknown Source)
    at com.jayway.restassured.internal.RequestSpecificationImpl.put(RequestSpecificationImpl.groovy:137)
    at com.jayway.restassured.specification.RequestSender$put.call(Unknown Source)
    at com.jayway.restassured.internal.ResponseSpecificationImpl.put(ResponseSpecificationImpl.groovy:232)
   

Johan Haleby

unread,
Apr 14, 2013, 5:16:12 AM4/14/13
to rest-a...@googlegroups.com
Hi, 

Thanks for your detailed explanation. You're right that REST Assured adds Content-Type=*/* if no content type is specified. If "*/*" is the problem can't use set a content type header yourself (given().contentType(..)...)? In that case REST Assured won't override it. Or are you saying that you don't want to include a content-type header at all?

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.
 
 

Jeff M

unread,
Apr 15, 2013, 11:10:22 AM4/15/13
to rest-a...@googlegroups.com
Hi Johan,

I am hoping to not include the content-type header at all.  Would it be possible to add another value to the ContentType enumeration, for example ContentType.Exclude, that would then signal your code to not put any entry for content-type in the headers?

Regards,

Jeff

Johan Haleby

unread,
Apr 16, 2013, 1:06:16 AM4/16/13
to rest-a...@googlegroups.com
I don't think that's possible right now :( Please add it as an issue to the issue tracker and I'll see what I can do. 

Regards,
/Johan


jmer...@innoventsolutions.com

unread,
Apr 16, 2013, 1:35:36 AM4/16/13
to rest-a...@googlegroups.com
Hi Johan,

I will add it to the issue tracker, and I will note it as low priority
since I can workaround this by using HttpClient. It might be a useful
feature for others, so maybe you can prioritize it accordingly.

Regards,

Jeff
>> For more options, visit https://groups.google.com/groups/opt_out [1].
>>  
>>  
>
> --
> You received this message because you are subscribed to a topic in
> the Google Groups "REST assured" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/rest-assured/Dnj7y6ntdQc/unsubscribe?hl=en
> [2].
> To unsubscribe from this group and all its topics, send an email to
> rest-assured...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out [1].
>
>
>
> Links:
> ------
> [1] https://groups.google.com/groups/opt_out
> [2]
> https://groups.google.com/d/topic/rest-assured/Dnj7y6ntdQc/unsubscribe?hl=en

Johan Haleby

unread,
Apr 16, 2013, 4:57:20 AM4/16/13
to rest-a...@googlegroups.com
Thanks


On Tue, Apr 16, 2013 at 7:35 AM, <jmer...@innoventsolutions.com> wrote:
Hi Johan,

I will add it to the issue tracker, and I will note it as low priority since I can workaround this by using HttpClient.  It might be a useful feature for others, so maybe you can prioritize it accordingly.

Regards,

Jeff


On 2013-04-15 22:06, Johan Haleby wrote:
I don't think that's possible right now :( Please add it as an issue
to the issue tracker and I'll see what I can do. 

Regards,
/Johan

On Mon, Apr 15, 2013 at 5:10 PM, Jeff M <jmericle@innoventsolutions.com> wrote:

Hi Johan,

I am hoping to not include the content-type header at all.  Would it be possible to add another value to the ContentType enumeration, for example ContentType.Exclude, that would then signal your code to not put any entry for content-type in the headers?

Regards,

Jeff

On Sunday, April 14, 2013 2:16:12 AM UTC-7, Johan Haleby wrote:

Hi, 

Thanks for your detailed explanation. You're right that REST Assured adds Content-Type=*/* if no content type is specified. If "*/*" is the problem can't use set a content type header yourself (given().contentType(..)...)? In that case REST Assured won't override it. Or are you saying that you don't want to include a content-type header at all?

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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out [1].
 
 

 --
 You received this message because you are subscribed to a topic in

the Google Groups "REST assured" group.
 To unsubscribe from this topic, visit
https://groups.google.com/d/topic/rest-assured/Dnj7y6ntdQc/unsubscribe?hl=en
[2].
 To unsubscribe from this group and all its topics, send an email to
--
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.
For more options, visit https://groups.google.com/groups/opt_out.



Reply all
Reply to author
Forward
0 new messages