diff --git a/radar-commons/src/main/java/org/radarbase/producer/schema/SchemaRestClient.kt b/radar-commons/src/main/java/org/radarbase/producer/schema/SchemaRestClient.kt index 1e85dab0..59fa1d11 100644 --- a/radar-commons/src/main/java/org/radarbase/producer/schema/SchemaRestClient.kt +++ b/radar-commons/src/main/java/org/radarbase/producer/schema/SchemaRestClient.kt @@ -2,10 +2,13 @@ package org.radarbase.producer.schema import io.ktor.client.HttpClient import io.ktor.client.call.body -import io.ktor.client.plugins.auth.* -import io.ktor.client.plugins.auth.providers.* import io.ktor.client.plugins.contentnegotiation.ContentNegotiation -import io.ktor.client.request.* +import io.ktor.client.plugins.defaultRequest +import io.ktor.client.request.HttpRequestBuilder +import io.ktor.client.request.accept +import io.ktor.client.request.request +import io.ktor.client.request.setBody +import io.ktor.client.request.url import io.ktor.http.ContentType import io.ktor.http.HttpMethod import io.ktor.http.contentType @@ -18,15 +21,13 @@ import kotlinx.coroutines.withContext import kotlinx.serialization.json.Json import org.apache.avro.Schema import org.radarbase.producer.rest.RestException.Companion.toRestException -import org.slf4j.LoggerFactory import java.io.IOException -import java.net.URI import kotlin.coroutines.CoroutineContext /** REST client for Confluent schema registry. */ class SchemaRestClient( httpClient: HttpClient, - private val baseUrl: String, + baseUrl: String, private val ioContext: CoroutineContext = Dispatchers.IO, ) { private val httpClient: HttpClient = httpClient.config { @@ -38,6 +39,10 @@ class SchemaRestClient( }, ) } + defaultRequest { + url(baseUrl) + accept(ContentType.Application.Json) + } } suspend inline fun request( @@ -83,7 +88,7 @@ class SchemaRestClient( @Throws(IOException::class) suspend fun schemaGet(path: String): SchemaMetadata = request { method = HttpMethod.Get - url(URI(baseUrl).resolve(path).toString()) + url(path) } @Throws(IOException::class) @@ -92,7 +97,7 @@ class SchemaRestClient( schema: Schema, ): SchemaMetadata = request { method = HttpMethod.Post - url(URI(baseUrl).resolve(path).toString()) + url(path) contentType(ContentType.Application.Json) setBody(SchemaMetadata(schema = schema.toString())) } @@ -127,8 +132,4 @@ class SchemaRestClient( schemaGet("/schemas/ids/$id") .toParsedSchemaMetadata(id) .schema - - companion object { - private val logger = LoggerFactory.getLogger(SchemaRestClient::class.java) - } } diff --git a/radar-commons/src/main/java/org/radarbase/producer/schema/SchemaRetriever.kt b/radar-commons/src/main/java/org/radarbase/producer/schema/SchemaRetriever.kt index 82824b2c..29d792b2 100644 --- a/radar-commons/src/main/java/org/radarbase/producer/schema/SchemaRetriever.kt +++ b/radar-commons/src/main/java/org/radarbase/producer/schema/SchemaRetriever.kt @@ -205,8 +205,8 @@ open class SchemaRetriever(config: Config) { @RadarProducerDsl class Config( val baseUrl: String, - var httpClient: HttpClient? = null, ) { + var httpClient: HttpClient? = null var schemaTimeout: CacheConfig = DEFAULT_SCHEMA_TIMEOUT_CONFIG var ioContext: CoroutineContext = Dispatchers.IO fun httpClient(config: HttpClientConfig<*>.() -> Unit) {