@@ -2,10 +2,13 @@ package org.radarbase.producer.schema
2
2
3
3
import io.ktor.client.HttpClient
4
4
import io.ktor.client.call.body
5
- import io.ktor.client.plugins.auth.*
6
- import io.ktor.client.plugins.auth.providers.*
7
5
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
8
- import io.ktor.client.request.*
6
+ import io.ktor.client.plugins.defaultRequest
7
+ import io.ktor.client.request.HttpRequestBuilder
8
+ import io.ktor.client.request.accept
9
+ import io.ktor.client.request.request
10
+ import io.ktor.client.request.setBody
11
+ import io.ktor.client.request.url
9
12
import io.ktor.http.ContentType
10
13
import io.ktor.http.HttpMethod
11
14
import io.ktor.http.contentType
@@ -18,15 +21,13 @@ import kotlinx.coroutines.withContext
18
21
import kotlinx.serialization.json.Json
19
22
import org.apache.avro.Schema
20
23
import org.radarbase.producer.rest.RestException.Companion.toRestException
21
- import org.slf4j.LoggerFactory
22
24
import java.io.IOException
23
- import java.net.URI
24
25
import kotlin.coroutines.CoroutineContext
25
26
26
27
/* * REST client for Confluent schema registry. */
27
28
class SchemaRestClient (
28
29
httpClient : HttpClient ,
29
- private val baseUrl : String ,
30
+ baseUrl : String ,
30
31
private val ioContext : CoroutineContext = Dispatchers .IO ,
31
32
) {
32
33
private val httpClient: HttpClient = httpClient.config {
@@ -38,6 +39,10 @@ class SchemaRestClient(
38
39
},
39
40
)
40
41
}
42
+ defaultRequest {
43
+ url(baseUrl)
44
+ accept(ContentType .Application .Json )
45
+ }
41
46
}
42
47
43
48
suspend inline fun <reified T > request (
@@ -83,7 +88,7 @@ class SchemaRestClient(
83
88
@Throws(IOException ::class )
84
89
suspend fun schemaGet (path : String ): SchemaMetadata = request {
85
90
method = HttpMethod .Get
86
- url(URI (baseUrl).resolve( path).toString() )
91
+ url(path)
87
92
}
88
93
89
94
@Throws(IOException ::class )
@@ -92,7 +97,7 @@ class SchemaRestClient(
92
97
schema : Schema ,
93
98
): SchemaMetadata = request {
94
99
method = HttpMethod .Post
95
- url(URI (baseUrl).resolve( path).toString() )
100
+ url(path)
96
101
contentType(ContentType .Application .Json )
97
102
setBody(SchemaMetadata (schema = schema.toString()))
98
103
}
@@ -127,8 +132,4 @@ class SchemaRestClient(
127
132
schemaGet(" /schemas/ids/$id " )
128
133
.toParsedSchemaMetadata(id)
129
134
.schema
130
-
131
- companion object {
132
- private val logger = LoggerFactory .getLogger(SchemaRestClient ::class .java)
133
- }
134
135
}
0 commit comments