use of org.apache.http.params.BasicHttpParams in project dhis2-core by dhis2.
the class HttpUtils method httpDELETE.
/**
* <pre>
* <b>Description : </b>
* Method to make an http DELETE call to a given URL with/without authentication.
*
* @param requestURL
* @param authorize
* @param username
* @param password
* @param headers
* @param timeout
* @return
* @throws Exception </pre>
*/
public static DhisHttpResponse httpDELETE(String requestURL, boolean authorize, String username, String password, Map<String, String> headers, int timeout) throws Exception {
DefaultHttpClient httpclient = null;
DhisHttpResponse dhisHttpResponse = null;
try {
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, timeout);
HttpConnectionParams.setSoTimeout(params, timeout);
httpclient = new DefaultHttpClient(params);
HttpDelete httpDelete = new HttpDelete(requestURL);
if (headers instanceof Map) {
for (Map.Entry<String, String> e : headers.entrySet()) {
httpDelete.addHeader(e.getKey(), e.getValue());
}
}
if (authorize) {
httpDelete.setHeader("Authorization", CodecUtils.getBasicAuthString(username, password));
}
HttpResponse response = httpclient.execute(httpDelete);
dhisHttpResponse = processResponse(requestURL, username, response);
return dhisHttpResponse;
} catch (Exception e) {
log.error("exception occurred in httpDELETE call with username " + username, e);
throw e;
} finally {
if (httpclient != null) {
httpclient.getConnectionManager().shutdown();
}
}
}
Aggregations