epugh commented on code in PR #1863:
URL: https://github.com/apache/solr/pull/1863#discussion_r1303190761


##########
solr/core/src/java/org/apache/solr/cli/ApiTool.java:
##########
@@ -61,29 +60,39 @@ public List<Option> getOptions() {
 
   @Override
   public void runImpl(CommandLine cli) throws Exception {
+    String response = null;
     String getUrl = cli.getOptionValue("get");
     if (getUrl != null) {
-      getUrl = getUrl.replace("+", "%20");
-      URI uri = new URI(getUrl);
-      String solrUrl = getSolrUrlFromUri(uri);
-      String path = uri.getPath();
-      try (var solrClient = SolrCLI.getSolrClient(solrUrl)) {
-        NamedList<Object> response =
-            solrClient.request(
-                // For path parameter we need the path without the root so 
from the second / char
-                // (because root can be configured)
-                // E.g URL is http://localhost:8983/solr/admin/info/system 
path is
-                // /solr/admin/info/system and the path without root is 
/admin/info/system
-                new GenericSolrRequest(
-                    SolrRequest.METHOD.GET,
-                    path.substring(path.indexOf("/", path.indexOf("/") + 1)),
-                    getSolrParamsFromUri(uri)));
+      response = callGet(getUrl);
+    }
+    if (response != null) {
+      // pretty-print the response to stdout
+      echo(response);
+    }
+  }
 
-        // pretty-print the response to stdout
-        CharArr arr = new CharArr();
-        new JSONWriter(arr, 2).write(response.asMap());
-        echo(arr.toString());
-      }
+  protected String callGet(String url) throws Exception {

Review Comment:
   I suspect that all the logic here in callGet is duplicated in other places 
around our codebase.....    I wish we had a single place to do these types of 
calls that we could reuse.     Maybe for another day. ;-).



##########
solr/core/src/test/org/apache/solr/cli/ApiToolTest.java:
##########
@@ -42,4 +58,48 @@ public void testParsingGetUrl() throws URISyntaxException {
       assertEquals("select id from COLL_NAME limit 10", params.get("stmt"));
     }
   }
+
+  @Test
+  public void testQueryResponse() throws Exception {
+    int docCount = 1000;
+    CollectionAdminRequest.createCollection(COLLECTION_NAME, "config", 2, 1)
+        .process(cluster.getSolrClient());
+    cluster.waitForActiveCollection(COLLECTION_NAME, 2, 2);
+
+    String tmpFileLoc =
+        new File(cluster.getBaseDir().toFile().getAbsolutePath() + 
File.separator).getPath();
+
+    UpdateRequest ur = new UpdateRequest();
+    ur.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
+
+    for (int i = 0; i < docCount; i++) {
+      ur.add(
+          "id",
+          String.valueOf(i),
+          "desc_s",
+          TestUtil.randomSimpleString(random(), 10, 50),
+          "a_dt",
+          "2019-09-30T05:58:03Z");
+    }
+    cluster.getSolrClient().request(ur, COLLECTION_NAME);
+
+    ApiTool tool = new ApiTool();
+
+    String response =
+        tool.callGet(
+            cluster.getJettySolrRunner(0).getBaseUrl()
+                + "/"
+                + COLLECTION_NAME
+                + "/select?q=*:*&rows=1&fl=id&sort=id+asc");
+    // Fields that could be missed because of serialization
+    assertFindInJson(response, "\"numFound\":1000,");
+    // Correct formatting
+    assertFindInJson(response, "\"docs\":[{");
+  }
+
+  private void assertFindInJson(String json, String find) {

Review Comment:
   sigh...    Don't we have this elsewhere defined ;-).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to