Skip to content

Commit

Permalink
ignore SSL cert validation
Browse files Browse the repository at this point in the history
  • Loading branch information
michaellifTelus committed Nov 1, 2021
1 parent b732783 commit 949c5d7
Showing 1 changed file with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package digital.capsa.it.runner
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.TextNode
import digital.capsa.it.json.JsonPathModifier
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.URI
import java.util.stream.Collectors
import org.apache.http.HttpHost
import org.apache.http.conn.ssl.NoopHostnameVerifier
import org.apache.http.conn.ssl.SSLConnectionSocketFactory
import org.apache.http.impl.client.HttpClientBuilder
import org.apache.http.impl.client.HttpClients
import org.apache.http.ssl.SSLContexts
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
import org.springframework.http.ResponseEntity
Expand All @@ -17,6 +17,10 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory
import org.springframework.stereotype.Component
import org.springframework.web.client.ResponseErrorHandler
import org.springframework.web.client.RestTemplate
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.URI
import java.util.stream.Collectors

@Component
class HttpRequestBuilder(private val objectMapper: ObjectMapper, private val requestFile: String) {
Expand Down Expand Up @@ -75,7 +79,7 @@ class HttpRequestBuilder(private val objectMapper: ObjectMapper, private val req
val response = restTemplate.exchange(
URI(httpRequest.schema, null, httpRequest.host, httpRequest.port,
(httpRequest.basePath?.let { "${httpRequest.basePath}" } ?: "")
+ httpRequest.path, httpRequest.queryParams, null).toString(),
+ httpRequest.path, httpRequest.queryParams, null).toString(),
httpRequest.method, requestEntity, String::class.java)

if (block != null) {
Expand All @@ -91,14 +95,24 @@ class HttpRequestBuilder(private val objectMapper: ObjectMapper, private val req
proxyHost: String?,
proxyPort: String?
):
HttpComponentsClientHttpRequestFactory {
HttpComponentsClientHttpRequestFactory {
val clientHttpRequestFactory = HttpComponentsClientHttpRequestFactory(
HttpClientBuilder.create()
.setProxy(proxyHost?.let { HttpHost(it, proxyPort!!.toInt(), "http") })
.build()
)
clientHttpRequestFactory.setConnectTimeout(connectTimeout)
clientHttpRequestFactory.setReadTimeout(readTimeout)
clientHttpRequestFactory.httpClient = HttpClients.custom()
.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.setSSLSocketFactory(
SSLConnectionSocketFactory(
SSLContexts.custom()
.loadTrustMaterial(null) { _, _ -> true }
.build(), null, null,
NoopHostnameVerifier()
)
).build()
return clientHttpRequestFactory
}
}

0 comments on commit 949c5d7

Please sign in to comment.