@ SuppressWarnings ( { "squid:S3776" , "squid:S2093" } ) private Response getResponse ( HttpURLConnection connection ) { int status ; Map headers ; try { status = connection . getResponseCode ( ) ; headers = connection . getHeaderFields ( ) ; } catch ( IOException e ) { log . error ( e ) ; return null ; } JsonObject object = null ; JsonArray array = null ; String data = null ; BufferedReader rd = null ; // unable to use the try-with-resources block, as the rd needs to be read in the finally, and can't be closed try { rd = new BufferedReader ( new InputStreamReader ( connection . getInputStream ( ) ) ) ; } catch ( IOException e ) { log . warn ( e ) ; try { rd = new BufferedReader ( new InputStreamReader ( connection . getErrorStream ( ) ) ) ; } catch ( NullPointerException ee ) { log . warn ( ee ) ; } } finally { StringBuilder sb = new StringBuilder ( ) ; String line ; if ( rd != null ) { try { while ( ( line = rd . readLine ( ) ) != null ) { sb . append ( line ) ; } } catch ( IOException e ) { log . error ( e ) ; } try { rd . close ( ) ; } catch ( IOException e ) { log . error ( e ) ; } data = sb . toString ( ) ; JsonParser parser = new JsonParser ( ) ; try { object = ( JsonObject ) parser . parse ( data ) ; } catch ( JsonSyntaxException | ClassCastException e ) { log . debug ( e ) ; try { array = ( JsonArray ) parser . parse ( data ) ; } catch ( JsonSyntaxException | ClassCastException ee ) { log . debug ( ee ) ; } } } } return new Response ( reporter , headers , status , object , array , data ) ; }
Extracts the response data from the open http connection