Source:
public CompletionStage<RestResponse> search(RestRequest restRequest) { NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder(); JsonQueryRequest query = null; if (restRequest.method() == Method.GET) { query = getQueryFromString(restRequest); } if (restRequest.method() == Method.POST || restRequest.method() == Method.PUT) { try { query = getQueryFromJSON(restRequest); } catch (IOException e) { return CompletableFuture.completedFuture(queryError("Invalid search request", e.getMessage())); } } if (query == null || query.getQuery() == null || query.getQuery().isEmpty()) { return CompletableFuture.completedFuture(queryError("Invalid search request, missing 'query' parameter", null)); } String cacheName = restRequest.variables().get("cacheName"); MediaType keyContentType = restRequest.keyContentType(); AdvancedCache<Object, Object> cache = restCacheManager.getCache(cacheName, keyContentType, MediaType.APPLICATION_JSON); String queryString = query.getQuery(); RemoteQueryManager remoteQueryManager = cache.getComponentRegistry().getComponent(RemoteQueryManager.class); JsonQueryRequest finalQuery = query; CompletionStage<RestResponse> future = CompletableFuture.supplyAsync(() -> { byte[] queryResultBytes = remoteQueryManager.executeQuery(queryString, emptyMap(), finalQuery.getStartOffset(), finalQuery.getMaxResults(), finalQuery.getQueryMode(), cache, MediaType.APPLICATION_JSON); responseBuilder.entity(queryResultBytes); return responseBuilder.build(); }, executor); return future.exceptionally(throwable -> queryError("Invalid search request", throwable.getMessage())); }

Target:
public CompletionStage<RestResponse> search(RestRequest restRequest) { NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder(); JsonQueryRequest query = null; if (restRequest.method() == Method.GET) { query = getQueryFromString(restRequest); } if (restRequest.method() == Method.POST || restRequest.method() == Method.PUT) { try { query = getQueryFromJSON(restRequest); } catch (IOException e) { return CompletableFuture.completedFuture(queryError("Invalid search request", e.getMessage())); } } if (query == null || query.getQuery() == null || query.getQuery().isEmpty()) { return CompletableFuture.completedFuture(queryError("Invalid search request, missing 'query' parameter", null)); } String cacheName = restRequest.variables().get("cacheName"); MediaType keyContentType = restRequest.keyContentType(); AdvancedCache<Object, Object> cache = restCacheManager.getCache(cacheName, keyContentType, MediaType.APPLICATION_JSON); String queryString = query.getQuery(); RemoteQueryManager remoteQueryManager = cache.getComponentRegistry().getComponent(RemoteQueryManager.class); JsonQueryRequest finalQuery = query; return CompletableFuture.supplyAsync(() -> { try { byte[] queryResultBytes = remoteQueryManager.executeQuery(queryString, emptyMap(), finalQuery.getStartOffset(), finalQuery.getMaxResults(), finalQuery.getQueryMode(), cache, MediaType.APPLICATION_JSON); responseBuilder.entity(queryResultBytes); return responseBuilder.build(); } catch (IllegalArgumentException | ParsingException | IllegalStateException e) { return queryError("Invalid search request", e.getMessage()); } }, executor); }