POST body not stored on tape when using HttpClient #50

perlyking opened this Issue Feb 7, 2012 · 4 comments


None yet
3 participants

My code under test uses Apache HttpClient to post some JSON content:

HttpPost httpPost = new HttpPost("http://foo.api")
httpPost.setHeader("Content-Type", "application/json")
HttpEntity reqEntity = new StringEntity(data, "UTF-8") // <- where data is a JSON string
response = httpClient.execute(httpPost) // <- Betamax proxy-configured httpClient

I was expecting to see the JSON appear in the tape file in the body section, but it's empty. I have also tried annotating my Spock test method to no effect:

import static betamax.MatchRule.*
@Betamax(match=[method, uri, body], tape="tape name")

I'm using Grails 1.3.7 and, in my buildConfig,

dependencies {
    test 'com.github.robfletcher:betamax:1.1-SNAPSHOT'
    compile("org.codehaus.groovy.modules.http-builder:http-builder:0.5.1") {
        excludes "groovy", "xml-apis"

Ookami86 commented Jun 8, 2012

Same issue here ... Here's a tiny project for you to reproduce the issue:

Run gradle test and take a at the created .yaml file.



robfletcher commented Aug 16, 2012

Thanks. I'll look into this.

For the record the match property on the annotation should make no difference to what gets stored in the tape, only the criteria used for determining if an existing recording is a match to the current request.

@robfletcher robfletcher pushed a commit that referenced this issue Aug 16, 2012

Rob Fletcher Failing test for #50 f1ed295

@robfletcher robfletcher pushed a commit that referenced this issue Aug 17, 2012

Rob Fletcher #50 check post body gets recorded with UrlConnection 71d27e2

robfletcher commented Aug 17, 2012

You can see from the test I've added in 71d27e2 that this doesn't work when using a UrlConnection either.


robfletcher commented Aug 17, 2012

The problem seems to be that org.eclipse.jetty.server.Request.getInputStream is always returning an empty stream. I presume I'm using it incorrectly but the code in the request & response abstraction is pretty messy anyway so I might attempt a rewrite as part of the fix.

robfletcher was assigned Aug 17, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment