public MPApiResponse executeRequest ( HttpMethod httpMethod , String uri , PayloadType payloadType , JsonObject payload , Collection < Header > colHeaders , int retries , int connectionTimeout , int socketTimeout ) throws MPRestException { HttpClient httpClient = null ; try { httpClient = getClient ( retries , connectionTimeout , socketTimeout ) ; if ( colHeaders == null ) { colHeaders = new Vector < Header > ( ) ; } HttpEntity entity = normalizePayload ( payloadType , payload , colHeaders ) ; HttpRequestBase request = getRequestMethod ( httpMethod , uri , entity ) ; for ( Header header : colHeaders ) { request . addHeader ( header ) ; } HttpResponse response ; long startMillis = System . currentTimeMillis ( ) ; try { response = httpClient . execute ( request ) ; } catch ( ClientProtocolException e ) { response = new BasicHttpResponse ( new BasicStatusLine ( request . getProtocolVersion ( ) , 400 , null ) ) ; } catch ( SSLPeerUnverifiedException e ) { response = new BasicHttpResponse ( new BasicStatusLine ( request . getProtocolVersion ( ) , 403 , null ) ) ; } catch ( IOException e ) { response = new BasicHttpResponse ( new BasicStatusLine ( request . getProtocolVersion ( ) , 404 , null ) ) ; } long endMillis = System . currentTimeMillis ( ) ; long responseMillis = endMillis - startMillis ; MPApiResponse mapiresponse = new MPApiResponse ( httpMethod , request , payload , response , responseMillis ) ; return mapiresponse ; } catch ( MPRestException restEx ) { throw restEx ; } catch ( Exception ex ) { throw new MPRestException ( ex ) ; } finally { try { if ( httpClient != null ) httpClient . getConnectionManager ( ) . shutdown ( ) ; } catch ( Exception ex ) { //Do Nothing } } }
Executes a http request and returns a response