private void sendRequest ( HttpUriRequest request , int expectedStatus ) throws Exception { addAuthHeader ( request ) ; HttpClient client = httpClient ( ) ; HttpResponse response = client . execute ( request ) ; if ( response . getStatusLine ( ) . getStatusCode ( ) == HttpStatus . SC_NOT_FOUND ) { EntityUtils . consume ( response . getEntity ( ) ) ; System . err . println ( "Authentication has been disabled for " + args . get ( 1 ) + "." ) ; } else if ( response . getStatusLine ( ) . getStatusCode ( ) == expectedStatus ) { if ( expectedStatus == HttpStatus . SC_OK ) { String responseStr = EntityUtils . toString ( response . getEntity ( ) ) ; List < String > usernames = new Gson ( ) . fromJson ( responseStr , new TypeToken < List < String > > ( ) { } . getType ( ) ) ; if ( usernames == null || usernames . isEmpty ( ) ) { System . out . println ( "There have been no site specific users created." ) ; } else { System . out . println ( usernames . size ( ) + " Users:" ) ; for ( String user : usernames ) { System . out . println ( user ) ; } } } } else { System . err . println ( EntityUtils . toString ( response . getEntity ( ) ) ) ; System . err . println ( "Unexpected status code returned. " + response . getStatusLine ( ) . getStatusCode ( ) ) ; } }
Sends a request to the rest endpoint .