throw new RuntimeException("You cannot send both form parameters and an entity body");
if (!request.getFormParameters().isEmpty())
{
commitHeaders(request, httpMethod);
PostMethod post = (PostMethod) httpMethod;
for (Map.Entry<String, List<String>> formParam : request.getFormParameters().entrySet())
{
List<String> values = formParam.getValue();
for (String value : values)
{
post.addParameter(formParam.getKey(), value);
}
}
}
else if (request.getBody() != null)
{
if (!(httpMethod instanceof EntityEnclosingMethod))
throw new RuntimeException("A GET request cannot have a body.");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
request.writeRequestBody(request.getHeadersAsObjects(), baos);
commitHeaders(request, httpMethod);
ClientRequestEntity requestEntity = new ClientRequestEntity(request.getBodyContentType().toString(), baos.toByteArray());
EntityEnclosingMethod post = (EntityEnclosingMethod) httpMethod;
post.setRequestEntity(requestEntity);
}
else
{
commitHeaders(request, httpMethod);
}