public Response makeJsonRequest ( Request request , OAuthMigrationRequest migrationRequest ) throws InvalidRequestException { logger . debug ( "Enter HttpRequestClient::makeJsonRequest" ) ; //create oauth consumer using tokens OAuthConsumer consumer = new CommonsHttpOAuthConsumer ( migrationRequest . getConsumerKey ( ) , migrationRequest . getConsumerSecret ( ) ) ; consumer . setTokenWithSecret ( migrationRequest . getAccessToken ( ) , migrationRequest . getAccessSecret ( ) ) ; HttpPost post = new HttpPost ( request . constructURL ( ) . toString ( ) ) ; //sign try { consumer . sign ( post ) ; } catch ( OAuthMessageSignerException e ) { logger . error ( "Exception while making httpRequest" , e ) ; throw new InvalidRequestException ( e . getMessage ( ) ) ; } catch ( OAuthExpectationFailedException e ) { logger . error ( "Exception while making httpRequest" , e ) ; throw new InvalidRequestException ( e . getMessage ( ) ) ; } catch ( OAuthCommunicationException e ) { logger . error ( "Exception while making httpRequest" , e ) ; throw new InvalidRequestException ( e . getMessage ( ) ) ; } //add headers post . setHeader ( "Accept" , "application/json" ) ; post . setHeader ( "Content-Type" , "application/json" ) ; // add post data HttpEntity entity = new StringEntity ( request . getPostJson ( ) , "UTF-8" ) ; post . setEntity ( entity ) ; CloseableHttpResponse httpResponse = null ; try { //make the call httpResponse = client . execute ( post ) ; //prepare response return new Response ( httpResponse . getEntity ( ) == null ? null : httpResponse . getEntity ( ) . getContent ( ) , httpResponse . getStatusLine ( ) . getStatusCode ( ) ) ; } catch ( ClientProtocolException e ) { logger . error ( "Exception while making httpRequest" , e ) ; throw new InvalidRequestException ( e . getMessage ( ) ) ; } catch ( IOException e ) { logger . error ( "Exception while making httpRequest" , e ) ; throw new InvalidRequestException ( e . getMessage ( ) ) ; } }
Method to make the HTTP POST request using the request attributes supplied