devmadhuu commented on code in PR #4540:
URL: https://github.com/apache/ozone/pull/4540#discussion_r1188399694


##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/http/SolrHttpClient.java:
##########
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.ozone.recon.http;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.NameValuePair;
+import org.apache.http.auth.AuthSchemeProvider;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.Credentials;
+import org.apache.http.client.config.AuthSchemes;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.config.Lookup;
+import org.apache.http.config.RegistryBuilder;
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
+import org.apache.http.conn.ssl.TrustStrategy;
+import org.apache.http.impl.auth.SPNegoSchemeFactory;
+import org.apache.http.impl.client.BasicCredentialsProvider;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.ssl.SSLContextBuilder;
+import org.apache.http.util.EntityUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Singleton;
+import java.io.IOException;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.Principal;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.List;
+
+/**
+ * This class is used to make http
+ * GET and POST requests to Apache Solr.
+ */
+@Singleton
+public class SolrHttpClient {
+  private static final Logger LOG =
+      LoggerFactory.getLogger(SolrHttpClient.class);
+
+  private static CloseableHttpClient httpClient;
+  private static HttpClientContext context;
+
+  public static CloseableHttpClient getCloseableHttpClient() {
+    if (null != httpClient) {
+      return httpClient;
+    }
+    try {
+      System.setProperty("sun.security.krb5.debug", "true");
+      System.setProperty("javax.security.auth.useSubjectCredsOnly", "false");
+      Lookup<AuthSchemeProvider> authSchemeRegistry =
+          RegistryBuilder.<AuthSchemeProvider>create()
+              .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true))
+              .build();
+      httpClient = HttpClients.custom()
+          .setSSLHostnameVerifier(
+              NoopHostnameVerifier.INSTANCE)
+          .setSSLContext(new SSLContextBuilder().loadTrustMaterial(
+              null, new TrustStrategy() {
+                public boolean isTrusted(X509Certificate[] arg0, String arg1)
+                    throws CertificateException {
+                  return true;
+                }
+              }).build())
+          .setDefaultAuthSchemeRegistry(authSchemeRegistry).build();
+    } catch (KeyManagementException e) {
+      LOG.error("KeyManagementException in creating http client instance", e);
+    } catch (NoSuchAlgorithmException e) {
+      LOG.error("NoSuchAlgorithmException in creating http client instance", 
e);
+    } catch (KeyStoreException e) {
+      LOG.error("KeyStoreException in creating http client instance", e);
+    }
+    return httpClient;

Review Comment:
   > httpClient can be null when above exceptions are thrown and catch , which 
in-turn will throw NPE in caller httpClient.execute(), better to propagate 
exception or handle NULL cases to avoid calling http execute method.
   
   Thanks @ashishkumar50 , this has been handled.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to