assert url.startsWith("http");
try {
client = createClient();
HttpUriRequest httpMethod = null;
switch (method) {
case GET:
httpMethod = new HttpGet(url);
break;
case DELETE:
httpMethod = new HttpDelete(url);
break;
case POST:
httpMethod = new HttpPost(url);
((HttpPost) httpMethod).setEntity(new StringEntity(this.requestBody));
break;
case PUT:
httpMethod = new HttpPut(url);
((HttpPut) httpMethod).setEntity(new StringEntity(this.requestBody));
break;
default:
throw new IllegalStateException("Can't execute this method : " + method);
}
//Adding headers
if (this.contentType == null){
this.contentType = SynchronousRestClient.xmlContentType;
}
httpMethod.addHeader("Content-type", this.contentType);
if (authorizationValue != null) {
httpMethod.addHeader("Authorization", ApacheRestClient.authorizationValue);
}
//Executing
HttpResponse httpResponse = client.execute(httpMethod);