![JAR search and dependency download from the Maven repository](/logo.png)
cloud.hedou.abp.remote.AbpHttpClient.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of abp-spring-boot-starter Show documentation
Show all versions of abp-spring-boot-starter Show documentation
When the functions of ABP cannot meet service requirements, the Spring Boot framework can be used to expand its own services to make use of abundant Java frameworks on the market.
package cloud.hedou.abp.remote
import com.fasterxml.jackson.databind.ObjectMapper
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.slf4j.LoggerFactory
import retrofit2.Retrofit
import retrofit2.converter.jackson.JacksonConverterFactory
import java.util.concurrent.TimeUnit
internal class AbpHttpClient(private val baseUrl: String, private val objectMapper: ObjectMapper) : HttpClient {
private val logger = LoggerFactory.getLogger(AbpHttpClient::class.java)
val okHttpClient: OkHttpClient by lazy {
OkHttpClient.Builder()
.callTimeout(8, TimeUnit.SECONDS)
.readTimeout(8, TimeUnit.SECONDS)
.writeTimeout(8, TimeUnit.SECONDS)
.addInterceptor(HeadersInterceptor())
.addInterceptor(HttpLoggingInterceptor(logger::info).setLevel(HttpLoggingInterceptor.Level.BODY))
.build()
}
val retrofit: Retrofit by lazy {
Retrofit.Builder()
.baseUrl(baseUrl)
.client(okHttpClient)
.addConverterFactory(JacksonConverterFactory.create(objectMapper))
.build()
}
override fun create(klass: Class): T {
val port = klass.getAnnotation(Api::class.java).port
return retrofit.newBuilder()
.baseUrl(retrofit.baseUrl().newBuilder().port(port).build())
.build()
.create(klass)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy