b.append(escapeString(key)).append("=").append(escapeString(value));
}
}
String querystring = b.toString();
Builder builder = client.resource(host + path + querystring).accept("application/json");
for(String key : headerParams.keySet()) {
builder.header(key, headerParams.get(key));
}
for(String key : defaultHeaderMap.keySet()) {
if(!headerParams.containsKey(key)) {
builder.header(key, defaultHeaderMap.get(key));
}
}
ClientResponse response = null;
if("GET".equals(method)) {
response = (ClientResponse) builder.get(ClientResponse.class);
}
else if ("POST".equals(method)) {
if(body == null)
response = builder.post(ClientResponse.class, null);
else if(body instanceof FormDataMultiPart) {
response = builder.type(contentType).post(ClientResponse.class, body);
}
else
response = builder.type(contentType).post(ClientResponse.class, serialize(body));
}
else if ("PUT".equals(method)) {
if(body == null)
response = builder.put(ClientResponse.class, serialize(body));
else {
if("application/x-www-form-urlencoded".equals(contentType)) {
StringBuilder formParamBuilder = new StringBuilder();
// encode the form params
for(String key : formParams.keySet()) {
String value = formParams.get(key);
if(value != null && !"".equals(value.trim())) {
if(formParamBuilder.length() > 0) {
formParamBuilder.append("&");
}
try {
formParamBuilder.append(URLEncoder.encode(key, "utf8")).append("=").append(URLEncoder.encode(value, "utf8"));
}
catch (Exception e) {
// move on to next
}
}
}
response = builder.type(contentType).put(ClientResponse.class, formParamBuilder.toString());
}
else
response = builder.type(contentType).put(ClientResponse.class, serialize(body));
}
}
else if ("DELETE".equals(method)) {
if(body == null)
response = builder.delete(ClientResponse.class, serialize(body));
else
response = builder.type(contentType).delete(ClientResponse.class, serialize(body));
}
else {
throw new ApiException(500, "unknown method type " + method);
}
if(response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) {