dsmiley commented on a change in pull request #994: SOLR-13662: Package Manager 
(CLI)
URL: https://github.com/apache/lucene-solr/pull/994#discussion_r345571223
 
 

 ##########
 File path: solr/core/src/java/org/apache/solr/packagemanager/PackageUtils.java
 ##########
 @@ -90,52 +88,123 @@ public static void postFile(SolrClient client, ByteBuffer 
buffer, String name, S
     }
   }
 
-  public static String getStringFromStream(String url) {
-    return get(url);
+  /**
+   * Download JSON from the url and deserialize into klass.
+   */
+  public static <T> T getJson(HttpClient client, String url, Class<T> klass) {
+    try {
+      return new ObjectMapper().readValue(getJson(client, url), klass);
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    } 
   }
 
-  public static String get(String url) {
-    try (CloseableHttpClient client = 
PackageUtils.createTrustAllHttpClientBuilder()) {
-      HttpGet httpGet = new HttpGet(url);
-      httpGet.setHeader("Content-type", "application/json");
-
-      CloseableHttpResponse response = client.execute(httpGet);
-
-      try {
-        HttpEntity rspEntity = response.getEntity();
-        if (rspEntity != null) {
-          InputStream is = rspEntity.getContent();
-          StringWriter writer = new StringWriter();
-          IOUtils.copy(is, writer, "UTF-8");
-          String results = writer.toString();
-
-          return(results);
-        }
-      } catch (IOException e) {
-        e.printStackTrace();
+  /**
+   * Search through the list of jar files for a given file. Returns string of
+   * the file contents or null if file wasn't found. This is suitable for 
looking
+   * for manifest or property files within pre-downloaded jar files.
+   */
+  public static String getFileFromArtifacts(List<Path> jars, String filename) {
+    for (Path jarfile: jars) {
+      try (ZipFile zipFile = new ZipFile(jarfile.toFile())) {
+        ZipEntry entry = zipFile.getEntry(filename);
+        if (entry == null) continue;
+        return IOUtils.toString(zipFile.getInputStream(entry));
+      } catch (Exception ex) {
+        throw new SolrException(ErrorCode.BAD_REQUEST, ex);
       }
-    } catch (Exception e1) {
-      throw new RuntimeException(e1);
     }
     return null;
   }
 
-  public static CloseableHttpClient createTrustAllHttpClientBuilder() throws 
Exception {
-    SSLContextBuilder builder = new SSLContextBuilder();
-    builder.loadTrustMaterial(null, (chain, authType) -> true);           
-    SSLConnectionSocketFactory sslsf = new 
-        SSLConnectionSocketFactory(builder.build(), 
NoopHostnameVerifier.INSTANCE);
-    return HttpClients.custom().setSSLSocketFactory(sslsf).build();
+  /**
+   * Returns JSON string from a given URL
+   */
+  public static String getJson(HttpClient client, String url) {
 
 Review comment:
   Rename: getJsonStringFromUrl

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to