@Test public void testMultiSearch() { AsyncHttpClient client = new AsyncHttpClient(); String s = "{\n" + " \"size\" : 0,\n" + " \"timeout\" : 5000,\n" + " \"query\" : {\n" + " \"constant_score\" : {\n" + " \"filter\" : {\n" + " \"bool\" : {\n" + " \"must\" : {\n" + " \"term\" : {\n" + " \"related-with\" : \"9da7320e-acd7-4f49-9b3f-4818f4afc67b\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"facets\" : {\n" + " \"frequently-related-with\" : {\n" + " \"terms\" : {\n" + " \"field\" : \"id\",\n" + " \"size\" : 10,\n" + " \"execution_hint\" : \"map\"\n" + " }\n" + " }\n" + " }\n" + "}\n"; HttpResult httpResult = AHCRequestExecutor.executeSearch(client, HttpMethod.GET,"http: System.out.println(httpResult.getResult()); try { SearchResponse r = SearchResponse.readSearchResponse(new ByteBufferStreamInput(ByteBuffer.wrap(httpResult.getResult().getBytes()))); System.out.println(r); } catch (IOException e) { e.printStackTrace(); } }
public static HttpResult executeSearch(AsyncHttpClient client, HttpMethod method, String host, String path, String searchQuery) { RequestBuilder requestBuilder = new RequestBuilder(method.name()); log.debug("Executing request against host {} with path {}",host,path); if(searchQuery!=null) { requestBuilder.setBody(searchQuery); } requestBuilder.setUrl(host + path); try { Response res = client.executeRequest(requestBuilder.build(),new AsyncCompletionHandlerBase()).get(); return new HttpResult(HttpSearchExecutionStatus.OK,res.getResponseBody()); } catch (Exception e) { Throwable cause = e.getCause(); if(cause!=null) { if(cause instanceof ConnectException) { log.error("Unable to connect to {}",host,e); return HttpResult.CONNECTION_FAILURE; } else if (cause instanceof TimeoutException) { log.error("Request timeout talking to {}",host,e); return HttpResult.REQUEST_TIMEOUT_FAILURE; } else if (cause instanceof IOException && cause.getMessage().equalsIgnoreCase("closed")) { log.warn("Unable to use client, client is closed"); return HttpResult.CLIENT_CLOSED; } else { log.error("Exception talking to {}",host,e); return new HttpResult(HttpSearchExecutionStatus.REQUEST_FAILURE,null); } } else { if (e instanceof IOException && e.getMessage().equalsIgnoreCase("closed")) { log.warn("Unable to use client, client is closed"); return HttpResult.CLIENT_CLOSED; } else { log.error("Exception talking to {}",host,e); return new HttpResult(HttpSearchExecutionStatus.REQUEST_FAILURE,null); } } } }
AHCRequestExecutor { public static HttpResult executeSearch(AsyncHttpClient client, HttpMethod method, String host, String path, String searchQuery) { RequestBuilder requestBuilder = new RequestBuilder(method.name()); log.debug("Executing request against host {} with path {}",host,path); if(searchQuery!=null) { requestBuilder.setBody(searchQuery); } requestBuilder.setUrl(host + path); try { Response res = client.executeRequest(requestBuilder.build(),new AsyncCompletionHandlerBase()).get(); return new HttpResult(HttpSearchExecutionStatus.OK,res.getResponseBody()); } catch (Exception e) { Throwable cause = e.getCause(); if(cause!=null) { if(cause instanceof ConnectException) { log.error("Unable to connect to {}",host,e); return HttpResult.CONNECTION_FAILURE; } else if (cause instanceof TimeoutException) { log.error("Request timeout talking to {}",host,e); return HttpResult.REQUEST_TIMEOUT_FAILURE; } else if (cause instanceof IOException && cause.getMessage().equalsIgnoreCase("closed")) { log.warn("Unable to use client, client is closed"); return HttpResult.CLIENT_CLOSED; } else { log.error("Exception talking to {}",host,e); return new HttpResult(HttpSearchExecutionStatus.REQUEST_FAILURE,null); } } else { if (e instanceof IOException && e.getMessage().equalsIgnoreCase("closed")) { log.warn("Unable to use client, client is closed"); return HttpResult.CLIENT_CLOSED; } else { log.error("Exception talking to {}",host,e); return new HttpResult(HttpSearchExecutionStatus.REQUEST_FAILURE,null); } } } } }
AHCRequestExecutor { public static HttpResult executeSearch(AsyncHttpClient client, HttpMethod method, String host, String path, String searchQuery) { RequestBuilder requestBuilder = new RequestBuilder(method.name()); log.debug("Executing request against host {} with path {}",host,path); if(searchQuery!=null) { requestBuilder.setBody(searchQuery); } requestBuilder.setUrl(host + path); try { Response res = client.executeRequest(requestBuilder.build(),new AsyncCompletionHandlerBase()).get(); return new HttpResult(HttpSearchExecutionStatus.OK,res.getResponseBody()); } catch (Exception e) { Throwable cause = e.getCause(); if(cause!=null) { if(cause instanceof ConnectException) { log.error("Unable to connect to {}",host,e); return HttpResult.CONNECTION_FAILURE; } else if (cause instanceof TimeoutException) { log.error("Request timeout talking to {}",host,e); return HttpResult.REQUEST_TIMEOUT_FAILURE; } else if (cause instanceof IOException && cause.getMessage().equalsIgnoreCase("closed")) { log.warn("Unable to use client, client is closed"); return HttpResult.CLIENT_CLOSED; } else { log.error("Exception talking to {}",host,e); return new HttpResult(HttpSearchExecutionStatus.REQUEST_FAILURE,null); } } else { if (e instanceof IOException && e.getMessage().equalsIgnoreCase("closed")) { log.warn("Unable to use client, client is closed"); return HttpResult.CLIENT_CLOSED; } else { log.error("Exception talking to {}",host,e); return new HttpResult(HttpSearchExecutionStatus.REQUEST_FAILURE,null); } } } }  }
AHCRequestExecutor { public static HttpResult executeSearch(AsyncHttpClient client, HttpMethod method, String host, String path, String searchQuery) { RequestBuilder requestBuilder = new RequestBuilder(method.name()); log.debug("Executing request against host {} with path {}",host,path); if(searchQuery!=null) { requestBuilder.setBody(searchQuery); } requestBuilder.setUrl(host + path); try { Response res = client.executeRequest(requestBuilder.build(),new AsyncCompletionHandlerBase()).get(); return new HttpResult(HttpSearchExecutionStatus.OK,res.getResponseBody()); } catch (Exception e) { Throwable cause = e.getCause(); if(cause!=null) { if(cause instanceof ConnectException) { log.error("Unable to connect to {}",host,e); return HttpResult.CONNECTION_FAILURE; } else if (cause instanceof TimeoutException) { log.error("Request timeout talking to {}",host,e); return HttpResult.REQUEST_TIMEOUT_FAILURE; } else if (cause instanceof IOException && cause.getMessage().equalsIgnoreCase("closed")) { log.warn("Unable to use client, client is closed"); return HttpResult.CLIENT_CLOSED; } else { log.error("Exception talking to {}",host,e); return new HttpResult(HttpSearchExecutionStatus.REQUEST_FAILURE,null); } } else { if (e instanceof IOException && e.getMessage().equalsIgnoreCase("closed")) { log.warn("Unable to use client, client is closed"); return HttpResult.CLIENT_CLOSED; } else { log.error("Exception talking to {}",host,e); return new HttpResult(HttpSearchExecutionStatus.REQUEST_FAILURE,null); } } } }  static HttpResult executeSearch(AsyncHttpClient client, HttpMethod method, String host,
                                     String path, String searchQuery); }
AHCRequestExecutor { public static HttpResult executeSearch(AsyncHttpClient client, HttpMethod method, String host, String path, String searchQuery) { RequestBuilder requestBuilder = new RequestBuilder(method.name()); log.debug("Executing request against host {} with path {}",host,path); if(searchQuery!=null) { requestBuilder.setBody(searchQuery); } requestBuilder.setUrl(host + path); try { Response res = client.executeRequest(requestBuilder.build(),new AsyncCompletionHandlerBase()).get(); return new HttpResult(HttpSearchExecutionStatus.OK,res.getResponseBody()); } catch (Exception e) { Throwable cause = e.getCause(); if(cause!=null) { if(cause instanceof ConnectException) { log.error("Unable to connect to {}",host,e); return HttpResult.CONNECTION_FAILURE; } else if (cause instanceof TimeoutException) { log.error("Request timeout talking to {}",host,e); return HttpResult.REQUEST_TIMEOUT_FAILURE; } else if (cause instanceof IOException && cause.getMessage().equalsIgnoreCase("closed")) { log.warn("Unable to use client, client is closed"); return HttpResult.CLIENT_CLOSED; } else { log.error("Exception talking to {}",host,e); return new HttpResult(HttpSearchExecutionStatus.REQUEST_FAILURE,null); } } else { if (e instanceof IOException && e.getMessage().equalsIgnoreCase("closed")) { log.warn("Unable to use client, client is closed"); return HttpResult.CLIENT_CLOSED; } else { log.error("Exception talking to {}",host,e); return new HttpResult(HttpSearchExecutionStatus.REQUEST_FAILURE,null); } } } }  static HttpResult executeSearch(AsyncHttpClient client, HttpMethod method, String host,
                                     String path, String searchQuery);  }