I have a third party REST endpoint that has a DELETE resource that requires specific body content. However, WireMock in proxy mode does NOT pass on this content. In fact, it also strips out the Content-Type and Content-Length headers.
To properly pass-through requests to the proxy target, WireMock should not be stripping any contents of the original request.
I see what you're saying. The underlying problem is that the Apache HTTP client doesn't support DELETE request entities, despite the fact they're allowed in the according to the HTTP spec.
I'm also seeing this behaviour with a GET request containing a request body (inherited code). The proxy strips the request body away resulting in completely different result from the target server.
Based on this resolved JIRA Issue:
https://issues.apache.org/jira/browse/HTTPCLIENT-1774
Unable to pass Json body to HttpDelete
this might be fixed in the HttpClient 5.0 Beta.
The underlying problem is that the Apache HTTP client doesn't support DELETE request entities, despite the fact they're allowed in the according to the HTTP spec.
We use Resteasy with org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine
and DELETE
methods work as expected, with content in body. Here's how our JAX-RS interface looks like:
@Path("/path")
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
public interface ClientIntf
{
@DELETE
@Path("/{pathParam}")
void deleteMethod(
POJP pojo,
@QueryParam("queryParam") String queryParam,
@PathParam("pathParam") String pathParam);
I see the request is captured by WireMock in recorder mode as expected, the body payload is there:
{
"id" : "8699c488-e035-4870-bf6e-c4c43b6ebd40",
"name" : "xxx",
"request" : {
"url" : "/path/pathParamValue?queryParam=queryParamValue",
"method" : "DELETE",
"bodyPatterns" : [ {
"equalToJson" : "{\"timestamp\":1721507271780,\"foo\":\"bar\"}",
"ignoreArrayOrder" : true,
"ignoreExtraElements" : true
} ]
},
"response" : {
"status" : 204,
"headers" : {
"Date" : "Wed, 24 Oct 2018 19:53:48 GMT"
}
},
"uuid" : "8699c488-e035-4870-bf6e-c4c43b6ebd40"
}
But when proxied further to a real service the body becomes empty.
Update:
Here's how they do it:
public class ApacheHttpClient4Engine ...
{
// ...
protected HttpRequestBase createHttpMethod(String url, String restVerb)
{
if ("GET".equals(restVerb))
{
return new HttpGet(url);
}
else if ("POST".equals(restVerb))
{
return new HttpPost(url);
}
else
{
final String verb = restVerb;
return new HttpPost(url)
{
@Override
public String getMethod()
{
return verb;
}
};
}
}
}
Hey,
I'm hitting this issue as well. Looks like the Apache HTTP client 5.0 now supports DELETE/GET requests with a body.
@tomakehurst do you have plans to upgrade to version 5.0 of the HTTP client in the future ?
Do you have any ideas how I can workaround this problem with the current HTTP client ?
Thanks
Most helpful comment
Hey,
I'm hitting this issue as well. Looks like the Apache HTTP client 5.0 now supports DELETE/GET requests with a body.
@tomakehurst do you have plans to upgrade to version 5.0 of the HTTP client in the future ?
Do you have any ideas how I can workaround this problem with the current HTTP client ?
Thanks