HttpUtil { public static HttpResponse executePostWithBasicAuth( final String url, final String userName, final String password ) { if ( StringUtils.isBlank( url ) ) { logger.warn( "In executePostWithBasicAuth, URL is either null or blank." ); return null; } HttpClient httpClient = HttpUtil.getHttpClientWithBasicAuth( userName, password ); if ( httpClient == null ) { logger.warn( "In executePostWithBasicAuth, unable to get HttpClient with BasicAuth." ); return null; } try { return httpClient.execute( new HttpPost( url ) ); } catch ( IOException e ) { logger.error( "In executePostWithBasicAuth, error invoking POST on '{}'", url, e ); return null; } }  static com.vmware.vrack.hms.common.HttpResponse executeRequest( String url, RequestMethod requestMethod,
                                                                           String requestBody ); static String buildUrl( List<String> list ); static T executeGet( final String url, final Class<T> valueType ); static T executeGet( final String url, final TypeReference<T> typeRef ); static HttpResponse executeGet( final String url ); static T executePost( final String url, final Object requestBody, final Class<T> valueType ); static T executePost( final String url, final Object requestBody, final TypeReference<T> typeRef ); static T executePost( final String url, final Class<T> valueType ); static T executePost( final String url, final TypeReference<T> typeRef ); static HttpResponse executePost( final String url ); static HttpResponse executePost( final String url, final Object requestBody ); static HttpResponse executePostWithBasicAuth( final String url, final String userName,
                                                         final String password ); static T executePostWithBasicAuth( final String url, final String userName, final String password,
                                                  final TypeReference<T> typeRef ); static T executePostWithBasicAuth( final String url, final String userName, final String password,
                                                  final Class<T> valueType ); static HttpClient getHttpClient(); static HttpResponse executePut( final String url ); static HttpResponse executePut( final String apiUrl, final String requestBody ); static final String RESP_CODE; static final String RESP_BODY; }
@Test public void testExecutePostWithBasicAuth() { final String url = "https: HttpResponse httpResponse = HttpUtil.executePostWithBasicAuth( url, "userName", "password" ); assertNotNull( httpResponse ); StatusLine statusLine = httpResponse.getStatusLine(); assertNotNull( statusLine ); assertTrue( statusLine.getStatusCode() == HttpStatus.SC_UNAUTHORIZED ); }