HttpUtil { public static <T> T executePost( final String url, final Object requestBody, final Class<T> valueType ) { if ( StringUtils.isBlank( url ) ) { logger.warn( "In executePost, URL is either null or blank.", url ); return null; } if ( requestBody == null ) { logger.warn( "In executePost, request body is null." ); return null; } if ( valueType == null ) { logger.warn( "In executePost, response type is null." ); return null; } HttpEntity httpEntity = HttpUtil.getStringEntity( requestBody ); if ( httpEntity == null ) { logger.warn( "In executePost, failed to serialize request body as JSON payload." ); return null; } return HttpUtil.executePost( url, httpEntity, HttpUtil.getResponseHandler( valueType ) ); }  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 testExecutePost() throws ParseException, IOException { HttpResponse httpResponse = HttpUtil.executePost( "http: + ServiceState.RUNNING.toString() ); assertNotNull( httpResponse ); assertTrue( httpResponse instanceof HttpResponse ); assertTrue( httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK ); }
@Test public void testExecutePostRequestBody() { HttpResponse httpResponse = HttpUtil.executePost( "http: assertNotNull( httpResponse ); assertTrue( httpResponse instanceof HttpResponse ); assertTrue( httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR ); }
@Test public void testExecutePostRequestBodyAndValueTypeResponse() { BaseResponse baseResponse = HttpUtil.executePost( "http: BaseResponse.class ); assertNull( baseResponse ); }
@Test public void testExecutePostWithoutRequestBodyAndTypeRefResponse() { TypeReference<Map<String, Object>> typeRef = new TypeReference<Map<String, Object>>() { }; Map<String, Object> sshKeyMap = HttpUtil.executePost( "http: assertNull( sshKeyMap ); }
@Test public void testExecutePostWithValueTypeResponse() throws ParseException, IOException { BaseResponse baseResponse = HttpUtil.executePost( "http: + ServiceState.RUNNING.toString(), BaseResponse.class ); assertNotNull( baseResponse ); assertTrue( baseResponse.getStatusCode() == HttpStatus.SC_NOT_MODIFIED ); }