JestHttpClient extends AbstractJestClient { protected HttpUriRequest constructHttpMethod(String methodName, String url, String payload, RequestConfig requestConfig) { HttpUriRequest httpUriRequest = null; if (methodName.equalsIgnoreCase("POST")) { httpUriRequest = new HttpPost(url); log.debug("POST method created based on client request"); } else if (methodName.equalsIgnoreCase("PUT")) { httpUriRequest = new HttpPut(url); log.debug("PUT method created based on client request"); } else if (methodName.equalsIgnoreCase("DELETE")) { httpUriRequest = new HttpDeleteWithEntity(url); log.debug("DELETE method created based on client request"); } else if (methodName.equalsIgnoreCase("GET")) { httpUriRequest = new HttpGetWithEntity(url); log.debug("GET method created based on client request"); } else if (methodName.equalsIgnoreCase("HEAD")) { httpUriRequest = new HttpHead(url); log.debug("HEAD method created based on client request"); } if (httpUriRequest instanceof HttpRequestBase && requestConfig != null) { ((HttpRequestBase) httpUriRequest).setConfig(requestConfig); } if (httpUriRequest != null && httpUriRequest instanceof HttpEntityEnclosingRequest && payload != null) { EntityBuilder entityBuilder = EntityBuilder.create() .setText(payload) .setContentType(requestContentType); if (isRequestCompressionEnabled()) { entityBuilder.gzipCompress(); } ((HttpEntityEnclosingRequest) httpUriRequest).setEntity(entityBuilder.build()); } return httpUriRequest; }  @Override T execute(Action<T> clientRequest); T execute(Action<T> clientRequest, RequestConfig requestConfig); @Override void executeAsync(final Action<T> clientRequest, final JestResultHandler<? super T> resultHandler); void executeAsync(final Action<T> clientRequest, final JestResultHandler<? super T> resultHandler, final RequestConfig requestConfig); @Override void shutdownClient(); @Override void close(); CloseableHttpClient getHttpClient(); void setHttpClient(CloseableHttpClient httpClient); CloseableHttpAsyncClient getAsyncClient(); void setAsyncClient(CloseableHttpAsyncClient asyncClient); Gson getGson(); void setGson(Gson gson); HttpClientContext getHttpClientContextTemplate(); void setHttpClientContextTemplate(HttpClientContext httpClientContext); void setElasticsearchVersion(ElasticsearchVersion elasticsearchVersion);  }
@Test public void constructGetHttpMethod() throws UnsupportedEncodingException { HttpUriRequest request = client.constructHttpMethod("GET", "jest/get", null, null); assertNotNull(request); assertEquals(request.getURI().getPath(), "jest/get"); assertTrue(request instanceof HttpGetWithEntity); }
@Test public void constructDeleteHttpMethodWithCustomRequestConfig() throws UnsupportedEncodingException { final RequestConfig requestConfig = RequestConfig.custom().setMaxRedirects(42).build(); HttpUriRequest request = client.constructHttpMethod("DELETE", "jest/delete", null, requestConfig); assertNotNull(request); assertEquals(requestConfig, ((HttpRequestBase) request).getConfig()); }
@Test public void constructHeadHttpMethodWithCustomRequestConfig() throws UnsupportedEncodingException { final RequestConfig requestConfig = RequestConfig.custom().setMaxRedirects(42).build(); HttpUriRequest request = client.constructHttpMethod("HEAD", "jest/head", null, requestConfig); assertNotNull(request); assertEquals(requestConfig, ((HttpRequestBase) request).getConfig()); }
@Test public void constructCompressedPutHttpMethod() throws UnsupportedEncodingException { client.setRequestCompressionEnabled(true); HttpUriRequest request = client.constructHttpMethod("PUT", "jest/put", "data", null); assertNotNull(request); assertEquals(request.getURI().getPath(), "jest/put"); assertTrue(request instanceof HttpPut); assertTrue(((HttpPut) request).getEntity() instanceof GzipCompressingEntity); }
@Test public void constructPutHttpMethod() throws UnsupportedEncodingException { HttpUriRequest request = client.constructHttpMethod("PUT", "jest/put", "data", null); assertNotNull(request); assertEquals(request.getURI().getPath(), "jest/put"); assertTrue(request instanceof HttpPut); assertFalse(((HttpPut) request).getEntity() instanceof GzipCompressingEntity); }
@Test public void constructPostHttpMethod() throws UnsupportedEncodingException { HttpUriRequest request = client.constructHttpMethod("POST", "jest/post", "data", null); assertNotNull(request); assertEquals(request.getURI().getPath(), "jest/post"); assertTrue(request instanceof HttpPost); }
@Test public void constructDeleteHttpMethod() throws UnsupportedEncodingException { HttpUriRequest request = client.constructHttpMethod("DELETE", "jest/delete", null, null); assertNotNull(request); assertEquals(request.getURI().getPath(), "jest/delete"); assertTrue(request instanceof HttpDeleteWithEntity); }
@Test public void constructHeadHttpMethod() throws UnsupportedEncodingException { HttpUriRequest request = client.constructHttpMethod("HEAD", "jest/head", null, null); assertNotNull(request); assertEquals(request.getURI().getPath(), "jest/head"); assertTrue(request instanceof HttpHead); }
@Test public void constructGetHttpMethodWithCustomRequestConfig() throws UnsupportedEncodingException { final RequestConfig requestConfig = RequestConfig.custom().setMaxRedirects(42).build(); HttpUriRequest request = client.constructHttpMethod("GET", "jest/get", null, requestConfig); assertNotNull(request); assertEquals(requestConfig, ((HttpRequestBase) request).getConfig()); }
@Test public void constructPutHttpMethodWithCustomRequestConfig() throws UnsupportedEncodingException { final RequestConfig requestConfig = RequestConfig.custom().setMaxRedirects(42).build(); HttpUriRequest request = client.constructHttpMethod("PUT", "jest/put", "data", requestConfig); assertNotNull(request); assertEquals(requestConfig, ((HttpRequestBase) request).getConfig()); }
@Test public void constructPostHttpMethodWithCustomRequestConfig() throws UnsupportedEncodingException { final RequestConfig requestConfig = RequestConfig.custom().setMaxRedirects(42).build(); HttpUriRequest request = client.constructHttpMethod("POST", "jest/post", "data", requestConfig); assertNotNull(request); assertEquals(requestConfig, ((HttpRequestBase) request).getConfig()); }