Does a POST request at path of the Impala web server and returns response. If the response does not include the expected status code, returns null. @param path URI path to query @param headers Headers to include in the POST; can be null @param params Parameters to include in the POST; can be null @p
(String path, Header[] headers, List<NameValuePair> params, int code)
| 145 | * @throws IOException if the request fails |
| 146 | */ |
| 147 | public String post(String path, Header[] headers, List<NameValuePair> params, int code) |
| 148 | throws IOException { |
| 149 | HttpHost target = new HttpHost(WEBSERVER_HOST, port_, "http"); |
| 150 | HttpClientContext context = getContext(target); |
| 151 | |
| 152 | HttpPost post = new HttpPost(path); |
| 153 | if (headers != null) { |
| 154 | post.setHeaders(headers); |
| 155 | } |
| 156 | if (params != null) { |
| 157 | post.setEntity(new UrlEncodedFormEntity(params)); |
| 158 | } |
| 159 | try (CloseableHttpResponse response = httpClient_.execute(target, post, context)) { |
| 160 | if (response.getStatusLine().getStatusCode() != code) { |
| 161 | return null; |
| 162 | } |
| 163 | return EntityUtils.toString(response.getEntity()); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | private HttpClientContext getContext(HttpHost targetHost) { |
| 168 | HttpClientContext context = HttpClientContext.create(); |
no test coverage detected