From ddcc79f9968f65f34bb049e469acfafe0a0aa2e9 Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Wed, 26 Apr 2023 12:14:16 -0400 Subject: Adding some minor features * Adding proxy and ssl context to CloseableHttpClient * Adding paged capability to ResourceDictionary GET API, and adding POST APi to bulk load resource definitions * Adding more packages to swagger-maven-plugin to get more RestCOntroller generating swagger doc * Fixing maven artifact versions all places Issue-ID: CCSDK-3895 Signed-off-by: Singal, Kapil (ks220y) Change-Id: I096f80a2326cd00068029330b241da209e46e31d (cherry picked from commit 2f4cc180555b1891fb749443449bd969db408d9c) --- .../rest/BluePrintRestLibData.kt | 1 + .../rest/service/BaseBlueprintWebClientService.kt | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'ms/blueprintsprocessor/modules/commons') diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt index a12680e07..6688f34e5 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/BluePrintRestLibData.kt @@ -26,6 +26,7 @@ open class RestClientProperties { var connectTimeout: Int = 0 var socketTimeout: Int = 0 var connectionRequestTimeout: Int = 0 + var proxy: String? = null var additionalHeaders: Map? = null } diff --git a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BaseBlueprintWebClientService.kt b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BaseBlueprintWebClientService.kt index 1505374be..41426d585 100644 --- a/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BaseBlueprintWebClientService.kt +++ b/ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/rest/service/BaseBlueprintWebClientService.kt @@ -24,6 +24,7 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.apache.commons.io.IOUtils import org.apache.http.HttpEntity +import org.apache.http.HttpHost import org.apache.http.HttpResponse import org.apache.http.HttpStatus import org.apache.http.client.ClientProtocolException @@ -35,6 +36,9 @@ import org.apache.http.client.methods.HttpPatch import org.apache.http.client.methods.HttpPost import org.apache.http.client.methods.HttpPut import org.apache.http.client.methods.HttpUriRequest +import org.apache.http.conn.ssl.NoopHostnameVerifier +import org.apache.http.conn.ssl.SSLContextBuilder +import org.apache.http.conn.ssl.TrustAllStrategy import org.apache.http.entity.StringEntity import org.apache.http.impl.client.CloseableHttpClient import org.apache.http.impl.client.HttpClients @@ -74,8 +78,24 @@ abstract class BaseBlueprintWebClientService : Blu return requestConfigBuilder.build() } + open fun https_proxy(): String? { + return getRestClientProperties().proxy + } + open fun httpClient(): CloseableHttpClient { - return HttpClients.custom() + var httpClients = HttpClients.custom() + if (https_proxy() != null && https_proxy() != "") { + val proxyProtocol = https_proxy()?.split(':')?.get(0) ?: "http" + val proxyUri = https_proxy()?.split(':')?.get(1)?.replace("/", "") ?: "" + val proxyPort = https_proxy()?.split(':')?.get(2)?.toInt() ?: 0 + if (proxyUri != "" && proxyPort != 0) { + val proxy = HttpHost(proxyUri, proxyPort, proxyProtocol) + httpClients = httpClients.setProxy(proxy) + .setSSLContext(SSLContextBuilder().loadTrustMaterial(null, TrustAllStrategy.INSTANCE).build()) + .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) + } + } + return httpClients .addInterceptorFirst(WebClientUtils.logRequest()) .addInterceptorLast(WebClientUtils.logResponse()) .setDefaultRequestConfig(getRequestConfig()) -- cgit 1.2.3-korg