diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java index a17e3dcb707..f35c0700eef 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java @@ -27,6 +27,7 @@ import org.apache.http.Consts; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.entity.ContentType; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; @@ -53,7 +54,7 @@ public class HandlerUtil { * @throws IOException IO exception returns if error occurs when executing the httpMethod */ public static ProxyResponse execute(HttpRequestBase httpRequest) throws IOException { - try (CloseableHttpClient client = HttpClients.createDefault()) { + try (CloseableHttpClient client = getHttpClient()) { HttpResponse response = client.execute(httpRequest); ProxyResponse proxyResponse = new ProxyResponse(); @@ -217,4 +218,18 @@ public class HandlerUtil { return gatewayPort; } + /** + * Retrieve Http client based on hostname verification. + * @return {@link CloseableHttpClient} http client + */ + public static CloseableHttpClient getHttpClient() { + boolean isIgnoreHostnameVerification = Boolean.parseBoolean(System. + getProperty("org.wso2.ignoreHostnameVerification")); + if (isIgnoreHostnameVerification) { + return HttpClients.custom().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build(); + } else { + return HttpClients.createDefault(); + } + } + }