Skip to content

Commit

Permalink
Merge pull request #166 from RADAR-base/revert-fix-schemaretriever
Browse files Browse the repository at this point in the history
revert "Move httpclient configuration into the config class"
  • Loading branch information
Bdegraaf1234 authored Jun 12, 2024
2 parents 114edc1 + d51f73d commit 73f35fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -38,6 +39,10 @@ class SchemaRestClient(
},
)
}
defaultRequest {
url(baseUrl)
accept(ContentType.Application.Json)
}
}

suspend inline fun <reified T> request(
Expand Down Expand Up @@ -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)
Expand All @@ -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()))
}
Expand Down Expand Up @@ -127,8 +132,4 @@ class SchemaRestClient(
schemaGet("/schemas/ids/$id")
.toParsedSchemaMetadata(id)
.schema

companion object {
private val logger = LoggerFactory.getLogger(SchemaRestClient::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 73f35fb

Please sign in to comment.