Search in sources :

Example 81 with BasicHttpParams

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();
        }
    }
}
Also used : BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) BasicHttpParams(org.apache.http.params.BasicHttpParams) Map(java.util.Map) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) IOException(java.io.IOException)

Aggregations

BasicHttpParams (org.apache.http.params.BasicHttpParams)81 HttpParams (org.apache.http.params.HttpParams)61 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)46 IOException (java.io.IOException)32 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)30 Scheme (org.apache.http.conn.scheme.Scheme)29 ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)28 HttpResponse (org.apache.http.HttpResponse)27 ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)23 ClientProtocolException (org.apache.http.client.ClientProtocolException)15 HttpClient (org.apache.http.client.HttpClient)12 HttpGet (org.apache.http.client.methods.HttpGet)12 Socket (java.net.Socket)11 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)11 HttpPost (org.apache.http.client.methods.HttpPost)10 ConnectException (java.net.ConnectException)8 SSLContext (javax.net.ssl.SSLContext)8 StringEntity (org.apache.http.entity.StringEntity)8 GeneralSecurityException (java.security.GeneralSecurityException)7 KeyManagementException (java.security.KeyManagementException)7