//make the communication
resourceURL = getApiServer() + resourceURL;
if(queryParams.keySet().size() > 0){
int i=0;
for(String paramName : queryParams.keySet()){
String symbol = "&";
if(i==0){
symbol = "?";
}
resourceURL = resourceURL + symbol + paramName + "=" + queryParams.get(paramName);
i++;
}
}
Map<String, String> headerMap = new HashMap<String, String>();
if(securityHandler != null){
securityHandler.populateSecurityInfo(resourceURL, headerMap);
}
WebResource aResource = apiClient.resource(resourceURL);
//set the required HTTP headers
Builder builder = aResource.type("application/json");
for(String key : headerMap.keySet()){
builder.header(key, headerMap.get(key));
}
if(headerParams != null){
for(String key : headerParams.keySet()){
builder.header(key, headerParams.get(key));
}
}
ClientResponse clientResponse = null;
if(method.equals(GET)) {
clientResponse = builder.get(ClientResponse.class);
}else if (method.equals(POST)) {
clientResponse = builder.post(ClientResponse.class, serialize(postData));
}else if (method.equals(PUT)) {
clientResponse = builder.put(ClientResponse.class, serialize(postData));
}else if (method.equals(DELETE)) {
clientResponse = builder.delete(ClientResponse.class);
}
//process the response
if(clientResponse.getClientResponseStatus() == ClientResponse.Status.OK) {
String response = clientResponse.getEntity(String.class);
return response;
}else{
int responseCode = clientResponse.getClientResponseStatus().getStatusCode() ;
throw new APIException(responseCode, clientResponse.getEntity(String.class));
}