public ResultT execute ( RequestT request ) throws IOException , NexmoClientException { try { RequestBuilder requestBuilder = applyAuth ( makeRequest ( request ) ) ; HttpUriRequest httpRequest = requestBuilder . build ( ) ; // If we have a URL Encoded form entity, we may need to regenerate it as UTF-8 // due to a bug (or two!) in RequestBuilder: // // This fix can be removed when HttpClient is upgraded to 4.5, although 4.5 also // has a bug where RequestBuilder.put(uri) and RequestBuilder.post(uri) use the // wrong encoding, whereas RequestBuilder.put().setUri(uri) uses UTF-8. // - MS 2017-04-12 if ( httpRequest instanceof HttpEntityEnclosingRequest ) { HttpEntityEnclosingRequest entityRequest = ( HttpEntityEnclosingRequest ) httpRequest ; HttpEntity entity = entityRequest . getEntity ( ) ; if ( entity instanceof UrlEncodedFormEntity ) { entityRequest . setEntity ( new UrlEncodedFormEntity ( requestBuilder . getParameters ( ) , Charset . forName ( "UTF-8" ) ) ) ; } else if ( entity instanceof StringEntity ) { // By default StringEntity is set to ISO-8859-1 but Nexmo expects UTF-8 entityRequest . setEntity ( new StringEntity ( EntityUtils . toString ( entity ) , Charset . forName ( "UTF-8" ) ) ) ; } } LOG . debug ( "Request: " + httpRequest ) ; if ( LOG . isDebugEnabled ( ) && httpRequest instanceof HttpEntityEnclosingRequestBase ) { HttpEntityEnclosingRequestBase enclosingRequest = ( HttpEntityEnclosingRequestBase ) httpRequest ; LOG . debug ( EntityUtils . toString ( enclosingRequest . getEntity ( ) ) ) ; } HttpResponse response = this . httpWrapper . getHttpClient ( ) . execute ( httpRequest ) ; return parseResponse ( response ) ; } catch ( UnsupportedEncodingException uee ) { throw new NexmoUnexpectedException ( "UTF-8 encoding is not supported by this JVM." , uee ) ; } }
Execute the REST call represented by this method object .