private JsonNode executeRequest ( HttpPost request ) throws IOException , GroovesharkException { HttpResponse response = httpClient . execute ( request ) ; if ( debugLogging ) { logRequest ( request , response ) ; } String responsePayload = CharStreams . toString ( new InputStreamReader ( response . getEntity ( ) . getContent ( ) , Charsets . UTF_8 ) ) ; // Parse response JSON try { return jsonMapper . readTree ( new StringReader ( responsePayload ) ) ; } catch ( JsonProcessingException e ) { throw new GroovesharkException . ServerErrorException ( "Failed to parse response - received data was not valid JSON: " + responsePayload ) ; } }
Boilerplate to send the request and parse the response payload as JSON .