Skip to content

Add xml support to actuator #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions daemon/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ dependencies {
implementation("org.springframework:spring-context-indexer")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
implementation("org.hibernate.orm:hibernate-community-dialects")
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("com.squareup.okhttp3:okhttp:4.10.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.krud.boost.daemon.actuator

import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.xml.XmlMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.KotlinModule
import dev.krud.boost.daemon.actuator.model.BeansActuatorResponse
Expand Down Expand Up @@ -44,6 +45,7 @@ import dev.krud.boost.daemon.okhttp.ProgressResponseBody
import okhttp3.Authenticator
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
Expand All @@ -67,6 +69,15 @@ class ActuatorHttpClientImpl(
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
}

internal val xmlMapper = XmlMapper().apply {
registerModule(JavaTimeModule())
registerModule(KotlinModule.Builder().build())
registerModule(
MultiDateParsingModule()
)
configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
}

private val baseHttpUrl: HttpUrl = baseUrl.toHttpUrl()

override fun testConnection(): TestConnectionResponse {
Expand Down Expand Up @@ -327,7 +338,11 @@ class ActuatorHttpClientImpl(
if (responseBody == null) {
throwInternalServerError("Actuator response body is null: $request")
} else {
objectMapper.readValue(responseBody, Type::class.java)
if (response.contentType()?.subtype?.contains("xml") == true) {
xmlMapper.readValue(responseBody, Type::class.java)
} else {
objectMapper.readValue(responseBody, Type::class.java)
}
}
}
}
Expand Down Expand Up @@ -401,6 +416,8 @@ class ActuatorHttpClientImpl(
}
}

private fun Response.contentType(): MediaType? = body?.contentType()

private fun getClient(block: OkHttpClient.Builder.() -> Unit = {}): OkHttpClient = OkHttpClient
.Builder()
.authenticator(authenticator)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package dev.krud.boost.daemon.actuator.model

import com.fasterxml.jackson.annotation.JsonProperty
import dev.krud.boost.daemon.utils.TypeDefaults
import jakarta.xml.bind.annotation.XmlElement

data class EndpointsActuatorResponse(
@JsonProperty("_links")
@XmlElement(name = "_links")
val links: Map<String, Link> = emptyMap()
) {
data class Link(
Expand Down