forked from Hakky54/mutual-tls-ssl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FuelService.kt
36 lines (29 loc) · 1.13 KB
/
FuelService.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package nl.altindag.client.service
import com.github.kittinunf.fuel.core.FuelManager
import com.github.kittinunf.fuel.httpGet
import nl.altindag.client.ClientType
import nl.altindag.client.ClientType.FUEL
import nl.altindag.client.Constants.HEADER_KEY_CLIENT_TYPE
import nl.altindag.client.model.ClientResponse
import nl.altindag.ssl.SSLFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
@Service
@Suppress("UNUSED_VARIABLE")
class FuelService(
@Autowired(required = false) sslFactory: SSLFactory?
): RequestService {
init {
sslFactory?.let { factory ->
FuelManager.instance.hostnameVerifier = factory.hostnameVerifier
FuelManager.instance.socketFactory = factory.sslSocketFactory
}
}
override fun executeRequest(url: String): ClientResponse {
val (request, response, result) = url.httpGet()
.header(HEADER_KEY_CLIENT_TYPE, clientType.value)
.responseString()
return ClientResponse(result.get(), response.statusCode)
}
override fun getClientType(): ClientType = FUEL
}