Build the Unirest {@link HttpRequest} that will be used to make the call to the API.

@param query The query to be made
@return Properly configured {@link HttpRequest} representing query
5215
private HttpRequest buildHTTPRequest(final Query<?, ?> query) {
		final String url = API_ENDPOINT + query.getPath();

		HttpRequest request;
		switch (query.getHttpRequestMethod()) {
			case GET:
				request = Unirest.get(url);

				if ((query.getQueryParameters() != null) && !query.getQueryParameters().isEmpty()) {
					((GetRequest) request).queryString(query.getQueryParameters());
				}

				break;

			case POST:
				request = Unirest.post(url);

				if ((query.getQueryParameters() != null) && !query.getQueryParameters().isEmpty()) {
					((HttpRequestWithBody) request).fields(query.getQueryParameters());
				}

				break;

			default:
				request = Unirest.get(url);
		}

		/*
		 * Add any named route parameters to the request (i.e. elements used to build the URI, such as
		 * '/sound/{sound_id}' would have a parameter named 'sound_id').
		 */
		if ((query.getRouteParameters() != null) && !query.getRouteParameters().isEmpty()) {
			for (final Entry<String, String> routeParameter : query.getRouteParameters().entrySet()) {
				request.routeParam(routeParameter.getKey(), routeParameter.getValue());
			}
		}

		return request;
	}
1290479
public static Map<String, String> queryToParams(String query) throws UnsupportedEncodingException {
		Map<String, String> query_pairs = new HashMap<String, String>();
		String[] pairs = query.split("&");
		for (String pair : pairs) {
			int idx = pair.indexOf("=");
			query_pairs.put(URLDecoder.decode(pair.substring(0, idx), "UTF-8"),
					URLDecoder.decode(pair.substring(idx + 1), "UTF-8"));
		}
		return query_pairs;
	}
1141654
public ApiResponse<QueryResponse> executeQueryPostWithHttpInfo(Query query) throws ApiException {
        com.squareup.okhttp.Call call = executeQueryPostValidateBeforeCall(query, null, null);
        Type localVarReturnType = new TypeToken<QueryResponse>(){}.getType();
        return apiClient.execute(call, localVarReturnType);
    }
429245
private Tree parseTree(HttpQuery query) {
    final Tree tree = new Tree(parseTreeId(query, false));
    if (query.hasQueryStringParam("name")) {
      tree.setName(query.getQueryStringParam("name"));
    }
    if (query.hasQueryStringParam("description")) {
      tree.setDescription(query.getQueryStringParam("description"));
    }
    if (query.hasQueryStringParam("notes")) {
      tree.setNotes(query.getQueryStringParam("notes"));
    }
    if (query.hasQueryStringParam("strict_match")) {
      if (query.getQueryStringParam("strict_match").toLowerCase()
          .equals("true")) {
        tree.setStrictMatch(true);
      } else {
        tree.setStrictMatch(false);
      }
    }
    if (query.hasQueryStringParam("enabled")) {
      final String enabled = query.getQueryStringParam("enabled");
      if (enabled.toLowerCase().equals("true")) {
        tree.setEnabled(true);
      } else {
        tree.setEnabled(false);
      }
    }
    if (query.hasQueryStringParam("store_failures")) {
      if (query.getQueryStringParam("store_failures").toLowerCase()
          .equals("true")) {
        tree.setStoreFailures(true);
      } else {
        tree.setStoreFailures(false);
      }
    }
    return tree;
  }
1113876
public ExecutionResult execute(String query) {
        ExecutionInput executionInput = ExecutionInput.newExecutionInput()
                .query(query)
                .build();
        return execute(executionInput);
    }
779375
public static String addStaticQueryParamtersToRequest(final Request<?> request,
                                                        final String uriResourcePath) {

        if (request == null || uriResourcePath == null) {
            return null;
        }

        String resourcePath = uriResourcePath;

        int index = resourcePath.indexOf("?");
        if (index != -1) {
            String queryString = resourcePath.substring(index + 1);
            resourcePath = resourcePath.substring(0, index);

            for (String s : queryString.split("[;&]")) {
                index = s.indexOf("=");
                if (index != -1) {
                    request.addParameter(s.substring(0, index), s.substring(index + 1));
                } else {
                    request.addParameter(s, (String)null);
                }
            }
        }
        return resourcePath;
    }
911355
public CqlQuery<K, N, V> setQuery(String query) {
    this.query = StringSerializer.get().toByteBuffer(query);
    return this;
  }
643993
@Override
    public SqlQueryResult build(String query) throws IOException, ParserNotFoundException {
        Operation result = (Operation) super.parse(query);

        // sql
        StringBuffer sql = new StringBuffer(result.getOperate());
        sql.delete(sql.length() - 2, sql.length());
        sql.delete(0, 2);

        return new SqlQueryResult(query, sql.toString(), (List<Object>) result.getValue());
    }
501914
public FutureData<DataSiftResult> start(FutureData<PreparedHistoricsQuery> query) {
        if (query == null) {
            throw new IllegalArgumentException("A valid PreparedHistoricsQuery is required");
        }
        final FutureData<DataSiftResult> future = new FutureData<>();
        DataSiftResult h = new BaseDataSiftResult();

        FutureResponse<PreparedHistoricsQuery> r = new FutureResponse<PreparedHistoricsQuery>() {
            public void apply(PreparedHistoricsQuery data) {
                if (data.getId() == null || data.getId().isEmpty()) {
                    throw new IllegalArgumentException("A valid PreparedHistoricsQuery is required");
                }
                start(data.getId(), future);
            }
        };
        unwrapFuture(query, future, h, r);
        return future;
    }
982398
public URIBuilder setQuery(final String query) {
		 this.queryParams = parseQuery(query, Consts.UTF_8);
		 this.encodedQuery = null;
		 this.encodedSchemeSpecificPart = null;
		 return this;
	 }
905491
@Override
    public final Query createQuery(String query)
    {
        checkClosed();
        checkTransactionNeeded();
        return getPersistenceDelegator().createQuery(query);
    }
507510
public static TSQuery parseQuery(final TSDB tsdb, final HttpQuery query) {
    return parseQuery(tsdb, query, null);
  }
653270
public void setQuery(String query) {

        try {
            m_parameters.setQuery(CmsEncoder.decodeParameter(query));
        } catch (CmsIllegalArgumentException iae) {
            m_lastException = iae;
        }
        resetLastResult();
    }
803264
public <T> CompletableFuture<T> submit(Query<T> query) {
    CompletableFuture<T> future = new CompletableFuture<>();
    context.executor().execute(() -> submitQuery(query, future));
    return future;
  }
807908
public HttpRequest buildDeleteRequest(GenericUrl url) throws IOException {
    return buildRequest(HttpMethods.DELETE, url, null);
  }
1014180
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);
                }
            }
        }
    }
139326
public HttpMessage queryParam(final String name, final String value) {
        if (!StringUtils.hasText(name)) {
            throw new CitrusRuntimeException("Invalid query param name - must not be empty!");
        }

        this.addQueryParam(name, value);

        final String queryParamString = queryParams.entrySet()
                .stream()
                .map(this::outputQueryParam)
                .collect(Collectors.joining(","));

        header(HttpMessageHeaders.HTTP_QUERY_PARAMS, queryParamString);
        header(DynamicEndpointUriResolver.QUERY_PARAM_HEADER_NAME, queryParamString);

        return this;
    }