Reuse okhttp3 instead of khttp

GitOrigin-RevId: 95644cca4ee8762295769a460439d92746db2fe7
This commit is contained in:
Vladimir Dolzhenko
2021-06-21 14:28:54 +02:00
committed by intellij-monorepo-bot
parent ce123c75dd
commit da2d9eab27
2 changed files with 43 additions and 27 deletions

View File

@@ -48,20 +48,24 @@
<orderEntry type="library" scope="TEST" name="jackson" level="project" />
<orderEntry type="library" scope="TEST" name="jackson-module-kotlin" level="project" />
<orderEntry type="module-library" scope="TEST">
<library name="khttp:khttp:1.0.0" type="repository">
<properties maven-id="khttp:khttp:1.0.0" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/khttp/khttp/1.0.0/khttp-1.0.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.1.1/kotlin-stdlib-1.1.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/json/json/20150729/json-20150729.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/spek/spek-api/1.1.0/spek-api-1.1.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-reflect/1.0.6/kotlin-reflect-1.0.6.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/spek/spek-junit-platform-engine/1.1.0/spek-junit-platform-engine-1.1.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
<library name="okhttp-4-9-0" type="repository">
<properties maven-id="com.squareup.okhttp3:okhttp:4.9.0">
<exclude>
<dependency maven-id="org.jetbrains:annotations" />
<dependency maven-id="org.jetbrains.kotlin:kotlin-stdlib-common" />
<dependency maven-id="org.jetbrains.kotlin:kotlin-stdlib" />
</exclude>
</properties>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/squareup/okhttp3/okhttp/4.9.0/okhttp-4.9.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/squareup/okio/okio/2.8.0/okio-2.8.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/squareup/okhttp3/okhttp/4.9.0/okhttp-4.9.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/squareup/okio/okio/2.8.0/okio-2.8.0-sources.jar!/" />
</SOURCES>
</library>
</orderEntry>
</component>
</module>

View File

@@ -2,9 +2,9 @@
package org.jetbrains.kotlin.idea.perf.util
import khttp.structures.authorization.BasicAuthorization
import java.io.FileInputStream
import java.util.*
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody
object ESUploader {
var host: String? = null
@@ -13,6 +13,9 @@ object ESUploader {
var indexName = "kotlin_ide_benchmarks"
private val JSON: MediaType = "application/json; charset=utf-8".toMediaType()
private val client = OkHttpClient()
init {
host = System.getenv("es.hostname")
username = System.getenv("es.username")
@@ -28,21 +31,30 @@ object ESUploader {
val url = "$host/$indexName/_doc/${benchmark.id()}"
val auth = if (username != null && password != null) {
BasicAuthorization(username!!, password!!)
Credentials.basic(username!!, password!!);
} else {
null
}
val json = kotlinJsonMapper.writeValueAsString(benchmark)
val response = khttp.put(
url = url,
auth = auth,
headers = mapOf("Content-Type" to "application/json"),
data = json
)
logMessage { "${response.statusCode} -> ${response.jsonObject}" }
if (response.statusCode != 200 && response.statusCode != 201) {
throw IllegalStateException("Error code ${response.statusCode} -> ${response.text}")
val body: RequestBody = json.toRequestBody(JSON)
val request: Request = Request.Builder()
.url(url)
.post(body)
.header("Content-Type", "application/json")
.also { builder ->
auth?.let {
builder.header("Authorization", it)
}
}
.build()
client.newCall(request).execute().use { response ->
val code = response.code
val string = response.body?.string()
logMessage { "$code -> $string" }
if (code != 200 && code != 201) {
throw IllegalStateException("Error code $code -> $string")
}
}
}
}