-
Notifications
You must be signed in to change notification settings - Fork 32
/
InstanceHttpClient.kt
49 lines (43 loc) · 1.72 KB
/
InstanceHttpClient.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
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.cognifide.gradle.aem.common.instance
import com.cognifide.gradle.aem.AemExtension
import com.cognifide.gradle.common.http.HttpClient
import com.cognifide.gradle.common.http.ResponseException
import org.apache.http.HttpResponse
@Suppress("MagicNumber")
open class InstanceHttpClient(private val aem: AemExtension, val instance: Instance) : HttpClient(aem.common) {
override fun throwStatusException(response: HttpResponse) {
throw ResponseException("Instance error. Unexpected response from $instance: ${response.statusLine}")
}
init {
baseUrl.set(instance.httpUrl.get())
escapeUrl.set(true)
if (instance.serviceCredentials.isPresent) {
val token = aem.obj.provider { aem.ims.generateToken(instance.serviceCredentials.asFile.get()) }
bearerToken.set(token)
} else {
authorizationPreemptive.set(true)
basicCredentials = instance.credentials
}
connectionTimeout.apply {
convention(30_000)
aem.prop.int("instance.http.connectionTimeout")?.let { set(it) }
}
connectionRetries.apply {
convention(true)
aem.prop.boolean("instance.http.connectionRetries")?.let { set(it) }
}
connectionIgnoreSsl.apply {
convention(true)
aem.prop.boolean("instance.http.connectionIgnoreSsl")?.let { set(it) }
}
proxyHost.apply {
aem.prop.string("instance.http.proxyHost")?.let { set(it) }
}
proxyPort.apply {
aem.prop.int("instance.http.proxyPort")?.let { set(it) }
}
proxyScheme.apply {
aem.prop.string("instance.http.proxyScheme")?.let { set(it) }
}
}
}