try {
final HttpClient client = clientFor(url);
final PostMethod post = new PostMethod(url.toString());
post.setDoAuthentication(true);
post.setRequestHeader("Accept", "application/json;stream=true");
final Gson gson = new Gson();
final String postData = gson.toJson(data);
post.setRequestEntity(new StringRequestEntity(postData, "application/json", "UTF-8"));
final int status = client.executeMethod(post);
if (status != 200) throw new RuntimeException("Return Status Code "+post.getStatusCode()+" "+post.getStatusLine());
return gson.fromJson(post.getResponseBodyAsString(), resultType);
} catch (Exception e) {
throw new RuntimeException("Error executing request to "+url+" with "+data+":" + e.getMessage());
}
}