protected Response getResponse ( HttpEntity entity , RequestBuilder req ) { CloseableHttpClient client = getClient ( ) ; initHeaders ( req ) ; req . setEntity ( entity ) ; CloseableHttpResponse resp = null ; Response response = null ; try { final HttpUriRequest uriRequest = req . build ( ) ; resp = client . execute ( uriRequest ) ; response = new Response ( resp ) ; response . setMethod ( Methods . POST . getMethod ( ) ) ; response . setRequestLine ( uriRequest . getRequestLine ( ) . toString ( ) ) ; } catch ( Exception e ) { // TODO: log the error e . printStackTrace ( ) ; } finally { try { client . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return response ; }
get response from preconfigured http entity and request builder